mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.0 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/package/base/sysfiles/stone_gui_text.sh
  9. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. # Use: gui_menu "ID" "Title" "Text" "Action" [ "Text" "Action" [ .. ] ]
  23. #
  24. gui_menu() {
  25. echo ; echo "+---" ; echo "$2" | fold -s -70 | sed 's,^,| ,'
  26. echo "+---" ; echo ; shift ; shift ; local nr=1 xnr=1 y in
  27. while [ $# -ge 2 ] ; do
  28. y="${2#\*}"
  29. if [ -z "$y" ] ; then
  30. if [ -z "$1" ] ; then
  31. echo " $1" ; shift ; shift
  32. else
  33. echo " - $1" ; shift ; shift
  34. fi
  35. else
  36. printf '%5d. %s\n' "$nr" "$1"
  37. eval "local action_$nr=\"\$y\""
  38. nr=$(( $nr + 1 )) ; shift ; shift
  39. fi
  40. xnr=$(( $xnr + 1 ))
  41. if [ $(( $xnr % 20 )) -eq 0 -a $# -gt 4 ] ; then
  42. echo ; echo -n ">> " ; read in || return 1
  43. [ "$in" ] && break
  44. echo
  45. fi
  46. done
  47. if [ -z "$in" ] ; then echo ; echo -n "> " ; read in ; fi
  48. in="action_$in" ; [ -z "${!in}" ] && return 1
  49. eval "${!in}" ; return 0
  50. }
  51. # Use: gui_input "Text" "Default" "VarName"
  52. #
  53. gui_input() {
  54. echo ; echo "+---" ; echo "$1" | fold -s -66 | sed 's,^,| ,'
  55. echo "+---" ; echo ; echo -n "[ $2 ] > " ; local tmp
  56. read tmp && [ -z "$tmp" ] && tmp="$2" ; eval "$3=\"\$tmp\""
  57. }
  58. # Use: gui_yesno "Text"
  59. #
  60. # [returns 0 if yes, 1 if no]
  61. gui_yesno() {
  62. local input y="[y]" n=" n "
  63. echo ; echo "+---"; echo "$1" | fold -s -66 | sed 's,^,| ,'
  64. echo "+---" ; echo
  65. while :; do
  66. echo -en "\r? $y\t$n"
  67. read -sr -n 1 input
  68. if [ "$input" = "" ]; then break
  69. elif [ "$input" = "y" ]; then y="[y]"; n=" n "
  70. elif [ "$input" = "n" ]; then y=" y "; n="[n]"
  71. fi
  72. done
  73. [ "$input" = "[y]" ] && return 0
  74. return 1
  75. }
  76. # Use: gui_message "Text"
  77. #
  78. gui_message() {
  79. echo ; echo "+---" ; echo "$1" | fold -s -66 | sed 's,^,| ,'
  80. echo "+---" ; echo ; echo "== Press ENTER to continue ==" ; read
  81. }
  82. # Use: gui_edit "Text" "File"
  83. #
  84. gui_edit() {
  85. # find editor
  86. for x in $EDITOR vi nvi emacs xemacs pico ; do
  87. if type -p $x > /dev/null
  88. then xx=$x ; break ; fi
  89. done
  90. if [ "$xx" ] ; then
  91. eval "$xx $2"
  92. else
  93. gui_message "Cannot find any editor. Make sure \$EDITOR is set."
  94. fi
  95. }
  96. # Use: gui_cmd "Title" "Command"
  97. #
  98. gui_cmd() {
  99. shift ; eval "$@"
  100. read -p "Press ENTER to continue."
  101. }