* updated tzdata (2024a -> 2024b)
[t2sde.git] / package / base / stone / stone_gui_text.sh
blob2ba5115c64491bf0b14a9ff79b7c4ac5ca949c2d
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/stone/stone_gui_text.sh
3 # Copyright (C) 2004 - 2023 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # Use: gui_menu "ID" "Title" "Text" "Action" [ "Text" "Action" [ .. ] ]
15 gui_menu() {
16 echo ; echo "+---" ; echo "$2" | fold -s -w70 | sed 's,^,| ,'
17 echo "+---" ; echo ; shift ; shift ; local nr=1 xnr=1 y in
19 while [ $# -ge 2 ] ; do
20 y="${2#\*}"
21 if [ -z "$y" ]; then
22 if [ -z "$1" ]; then
23 echo " $1" ; shift ; shift
24 else
25 echo " - $1" ; shift ; shift
27 else
28 printf '%5d. %s\n' "$nr" "$1"
29 eval "local action_$nr=\"\$y\""
30 (( nr++ )) ; shift ; shift
32 (( xnr++ ))
33 if [ $(( $xnr % 20 )) -eq 0 -a $# -gt 4 ]; then
34 echo ; echo -n ">> " ; read in || return 1
35 [ "$in" ] && break
36 echo
38 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
45 # Use: gui_input "Text" "Default" "VarName"
47 gui_input() {
48 echo ; echo "+---" ; echo "$1" | fold -s -w66 | sed 's,^,| ,'
49 echo "+---" ; echo ; echo -n "[ $2 ] > " ; local tmp
50 read tmp && [ -z "$tmp" ] && tmp="$2" ; eval "$3=\"\$tmp\""
53 # Use: gui_yesno "Text"
55 # [returns 0 if yes, 1 if no]
56 gui_yesno() {
57 local input y="[y]" n=" n "
59 echo ; echo "+---"; echo "$1" | fold -s -w66 | sed 's,^,| ,'
60 echo "+---" ; echo
62 while :; do
63 echo -en "\r? $y\t$n"
64 read -sr -n 1 input
66 if [ "$input" = "" ]; then break
67 elif [ "$input" = "y" ]; then y="[y]"; n=" n "
68 elif [ "$input" = "n" ]; then y=" y "; n="[n]"
70 done
72 [ "$y" = "[y]" ] && return 0
73 return 1
76 # Use: gui_message "Text"
78 gui_message() {
79 echo ; echo "+---" ; echo "$1" | fold -s -w66 | sed 's,^,| ,'
80 echo "+---" ; echo ; echo "== Press ENTER to continue ==" ; read
83 # Use: gui_edit "Text" "File"
85 gui_edit() {
86 # find editor
87 for x in $EDITOR vi nvi emacs xemacs pico ; do
88 if type -p $x > /dev/null
89 then xx=$x ; break; fi
90 done
91 if [ "$xx" ]; then
92 eval "$xx $2"
93 else
94 gui_message "Cannot find any editor. Make sure \$EDITOR is set."
98 # Use: gui_cmd "Title" "Command"
100 gui_cmd() {
101 shift ; eval "$@"
102 read -p "Press ENTER to continue."