source: trunk/dsys/funcDIALOG@ 1

Last change on this file since 1 was 1, checked in by katerina, 19 years ago

Initial import

File size: 5.4 KB
Line 
1#########################################################################
2#
3# Interaction Subroutines
4#
5#########################################################################
6
7# print without newline
8#
9printASK() {
10 echo $ECHO_N "$@ $ECHO_C"
11}
12
13# find a 'dialog' program
14#
15findDIALOG() {
16
17 if test x"$DIALOG" = xno
18 then
19 DIALOG=""; return 0
20 elif test -n "$DIALOG"
21 then
22 return 0
23 fi
24
25 PATH=/usr/local/bin:/usr/local/sbin:$PATH; export PATH
26 X="$PATH"
27 progs="dialog";
28 OLD_IFS=${IFS}
29 IFS=':'; export IFS
30 for dir in $X; do
31 for dia in $progs; do
32 dialog="$dir/$dia"
33 if (test -f "$dialog" || test -f "$dialog.exe")
34 then
35 if "$dialog" 2>&1 | grep tailbox >/dev/null 2>&1
36 then
37 IFS=${OLD_IFS}; export IFS
38 DIALOG="$dialog"; export DIALOG
39 return 0
40 fi
41 fi
42 done
43 done
44 IFS=${OLD_IFS}; export IFS
45 DIALOG=""; export DIALOG
46}
47
48
49# prompt user for yes/no
50#
51promptYESNO() {
52 if test $# -lt 1
53 then
54 printFATAL "promptYESNO: insufficient arguments"
55 fi
56
57 if test $silent -gt 1
58 then
59 YESNO=y; export YESNO
60 return 0
61 fi
62
63 DEFAULT=""
64 case "$2" in
65 [yY]|[yY][eE][sS])
66 DEFAULT=y ;;
67 [nN]|[nN][oO])
68 DEFAULT=n ;;
69 esac
70
71 YESNO=""
72
73 if test -n "$DIALOG"
74 then
75
76 if test x"$assumeyes" = x1
77 then
78 YESNO="$DEFAULT"; export YESNO
79 return 0
80 fi
81
82 "$DIALOG" --title "deploy.sh $version" --yesno "$1" 10 75 2>"$tmpF"
83 mtest=$?
84 if test x"$mtest" = "x-1"
85 then
86 printFATAL "promptYESNO: something went wrong"
87 elif test x"$mtest" = x0
88 then
89 YESNO=y
90 else
91 YESNO=n
92 fi
93 else
94 while :
95 do
96 if test x"$DEFAULT" = xy
97 then
98 printASK "$1 (Y/n) ?"
99 elif test x"$DEFAULT" = xn
100 then
101 printASK "$1 (N/y) ?"
102 else
103 printASK "$1 (y/n) ?"
104 fi
105
106 if test x"$assumeyes" = x1
107 then
108 YESNO="$DEFAULT"; export YESNO
109 echo "$DEFAULT"
110 return 0
111 fi
112
113 read YESNO
114 if test -z "$YESNO"
115 then
116 YESNO="$DEFAULT"
117 fi
118
119 case "$YESNO" in
120 [yY]|[yY][eE][sS])
121 YESNO=y; break ;;
122 [nN]|[nN][oO])
123 YESNO=n; break ;;
124 *)
125 YESNO="" ;;
126 esac
127 done
128 fi
129 export YESNO
130 return 0
131}
132
133# get user input from tmp file
134#
135getINPUT() {
136 INPUT=`cat $tmpF`
137 export INPUT
138 return 0
139}
140
141# info box
142#
143promptINFO() {
144 if test $# -lt 1
145 then
146 printFATAL "promptINPUT: insufficient arguments"
147 fi
148
149 if test x"$silent" != x0
150 then
151 return 0
152 fi
153
154 if test -n "$DIALOG"
155 then
156 "$DIALOG" --title "deploy.sh $version" --sleep 2 --infobox "$1" 8 75
157 else
158 echo $1
159 fi
160 return 0
161}
162
163# prompt user for input
164#
165promptINPUT() {
166 if test $# -lt 1
167 then
168 printFATAL "promptINPUT: insufficient arguments"
169 fi
170
171 if test $assumeyes -gt 0
172 then
173 printFATAL "promptINPUT: user interaction required"
174 fi
175
176 INPUT=""
177 DEFAULT="$2"
178
179 if test -n "$DIALOG"
180 then
181 "$DIALOG" --title "deploy.sh $version" --inputbox "$1" 16 75 "$2" 2>"$tmpF"
182 mtest=$?
183 if test x"$mtest" = "x1"
184 then
185 # cancel button
186 (exit 0); exit 0;
187 fi
188 if test x"$mtest" = "x-1"
189 then
190 printFATAL "promptINPUT: something went wrong"
191 else
192 getINPUT
193 fi
194 else
195
196 while :
197 do
198 if test -z "$DEFAULT"
199 then
200 printASK "$1 ?"
201 else
202 printASK "$1 ? $DEFAULT"
203 fi
204
205 read INPUT
206
207 if test -z "$INPUT"
208 then
209 if test -n "$DEFAULT"
210 then
211 locINPUT="$DEFAULT"
212 break
213 fi
214 elif test -n "$INPUT"
215 then
216 break
217 fi
218 done
219 export INPUT
220 fi
221 return 0
222}
223
224# get MENU from tmp file
225#
226getMENU() {
227 MENU=`cat $tmpF`
228 export MENU
229 return 0
230}
231
232# prompt user for options from menu
233#
234promptMENU() {
235 if test $# -lt 2
236 then
237 printFATAL "promptMENU: insufficient arguments"
238 fi
239
240 if test $assumeyes -gt 0
241 then
242 printFATAL "promptMENU: user interaction required"
243 fi
244
245 TITLE="$1"
246 shift
247
248 if test -n "$DIALOG"
249 then
250 #command="'$DIALOG' '--title' \\'deploy.sh $version\\' '--backtitle'"
251 #command="$command \'$TITLE\' '--menu' \'$TITLE\' '16' '75' '$#'"
252
253 argc=$#
254 if test $argc -gt 7
255 then
256 argc=7
257 fi
258
259 command="'$1' '' 'on'"
260 shift
261
262 for item
263 do
264 command="$command '$item' '' 'off'"
265 done
266
267 command="$command "
268
269 # printFATAL "$command"
270 eval $DIALOG '--title' \'deploy.sh $version\' '--backtitle' \'$TITLE\' '--radiolist' \'$TITLE\' '16' '75' $argc $command 2>"$tmpF"
271
272 mtest=$?
273
274 if test x"$mtest" = "x1"
275 then
276 # cancel button
277 (exit 0); exit 0;
278 fi
279 if test x"$mtest" = "x-1"; then
280 printFATAL "promptMENU: something went wrong"
281 else
282 getMENU
283 fi
284 else
285
286 MENU=""
287 INPUT=""
288
289 while :
290 do
291 clear
292 echo
293 echo "$TITLE"
294 echo
295 echo " 1) $1"
296 test -n "$2" && echo " 2) $2"
297 test -n "$3" && echo " 3) $3"
298 test -n "$4" && echo " 4) $4"
299 test -n "$5" && echo " 5) $5"
300 test -n "$6" && echo " 6) $6"
301 test -n "$7" && echo " 7) $7"
302 test -n "$8" && echo " 8) $8"
303 test -n "$9" && echo " 9) $9"
304 echo
305 printASK "Please enter your choice: "
306
307 read INPUT
308
309 if echo "$INPUT" | grep '[^0123456789]' >/dev/null 2>&1
310 then
311 :
312 elif test $INPUT -gt $#
313 then
314 :
315 else
316 break
317 fi
318 done
319
320 case "$INPUT" in
321 1) MENU="$1"; break ;;
322 2) MENU="$2"; break ;;
323 3) MENU="$3"; break ;;
324 4) MENU="$4"; break ;;
325 5) MENU="$5"; break ;;
326 6) MENU="$6"; break ;;
327 7) MENU="$7"; break ;;
328 8) MENU="$8"; break ;;
329 9) MENU="$9"; break ;;
330 esac
331
332 export MENU
333 fi
334 return 0
335}
336
Note: See TracBrowser for help on using the repository browser.