OpenSDE Packages Database (without history before r20070)
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.

108 lines
2.6 KiB

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