* updated krdc (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / base / stone / stone_gui_text.sh
blobf509cc3e8dda12b372bc24b6eaffab620e37e5d7
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 - 2021 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
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 ---
16 # Use: gui_menu "ID" "Title" "Text" "Action" [ "Text" "Action" [ .. ] ]
18 gui_menu() {
19 echo ; echo "+---" ; echo "$2" | fold -s -w70 | sed 's,^,| ,'
20 echo "+---" ; echo ; shift ; shift ; local nr=1 xnr=1 y in
22 while [ $# -ge 2 ] ; do
23 y="${2#\*}"
24 if [ -z "$y" ] ; then
25 if [ -z "$1" ] ; then
26 echo " $1" ; shift ; shift
27 else
28 echo " - $1" ; shift ; shift
30 else
31 printf '%5d. %s\n' "$nr" "$1"
32 eval "local action_$nr=\"\$y\""
33 (( nr++ )) ; shift ; shift
35 (( xnr++ ))
36 if [ $(( $xnr % 20 )) -eq 0 -a $# -gt 4 ] ; then
37 echo ; echo -n ">> " ; read in || return 1
38 [ "$in" ] && break
39 echo
41 done
43 if [ -z "$in" ] ; then echo ; echo -n "> " ; read in ; fi
44 in="action_$in" ; [ -z "${!in}" ] && return 1
45 eval "${!in}" ; return 0
48 # Use: gui_input "Text" "Default" "VarName"
50 gui_input() {
51 echo ; echo "+---" ; echo "$1" | fold -s -w66 | sed 's,^,| ,'
52 echo "+---" ; echo ; echo -n "[ $2 ] > " ; local tmp
53 read tmp && [ -z "$tmp" ] && tmp="$2" ; eval "$3=\"\$tmp\""
56 # Use: gui_yesno "Text"
58 # [returns 0 if yes, 1 if no]
59 gui_yesno() {
60 local input y="[y]" n=" n "
62 echo ; echo "+---"; echo "$1" | fold -s -w66 | sed 's,^,| ,'
63 echo "+---" ; echo
65 while :; do
66 echo -en "\r? $y\t$n"
67 read -sr -n 1 input
69 if [ "$input" = "" ]; then break
70 elif [ "$input" = "y" ]; then y="[y]"; n=" n "
71 elif [ "$input" = "n" ]; then y=" y "; n="[n]"
73 done
75 [ "$input" = "[y]" ] && return 0
76 return 1
79 # Use: gui_message "Text"
81 gui_message() {
82 echo ; echo "+---" ; echo "$1" | fold -s -w66 | sed 's,^,| ,'
83 echo "+---" ; echo ; echo "== Press ENTER to continue ==" ; read
86 # Use: gui_edit "Text" "File"
88 gui_edit() {
89 # find editor
90 for x in $EDITOR vi nvi emacs xemacs pico ; do
91 if type -p $x > /dev/null
92 then xx=$x ; break ; fi
93 done
94 if [ "$xx" ] ; then
95 eval "$xx $2"
96 else
97 gui_message "Cannot find any editor. Make sure \$EDITOR is set."
101 # Use: gui_cmd "Title" "Command"
103 gui_cmd() {
104 shift ; eval "$@"
105 read -p "Press ENTER to continue."