2 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
5 # copyright 2002 lmoore@tump.com under the terms of the GNU LGPL.
6 # additions 2005 collective@riseup.net
8 # whiptail has trouble being called in the foo=$(whiptail ...) fashion for
9 # some reason. this is very annoying. this means that we need to use
10 # temporary files to store the answers from the input and list based boxes
11 # and then read the answers into a REPLY variable. that just really
12 # stinks, oh well, that's what you get when you have a weak link
15 # inputBox and passwordBox could be refactored to use a common function
17 test -z "$WIDTH" && WIDTH=0
18 test -z "$HEIGHT" && HEIGHT=0
23 setApplicationTitle() {
37 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
38 `[ "$3" == no ] && echo '--defaultno'` --yesno "$2" $HEIGHT $WIDTH
42 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
43 --msgbox "$2" $HEIGHT $WIDTH
47 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
48 --gauge "$2" $HEIGHT $WIDTH 0
52 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
55 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
56 --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp
58 [ $status = 0 ] && REPLY=$(cat $temp)
63 # Xdialog and {dialog,whiptail} use different mechanism to "qoute" the
64 # values from a checklist. {dialog,whiptail} uses standard double quoting
65 # while Xdialog uses a "/" as the separator. the slash is arguably better,
66 # but the double quoting is more standard. anyway, this function can be
67 # overridden to allow a derived implementation to change it's quoting
68 # mechanism to the standard double-quoting one. it receives two
69 # arguements, the file that has the data and the box type.
74 # this is the base implementation of all the list based boxes, it works
75 # out nicely that way. the real function just passes it's arguments to
76 # this function with an extra argument specifying the actual box that
77 # needs to be rendered.
84 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
87 $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \
88 $box "$text" $HEIGHT $WIDTH 10 \
91 [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box)
98 _DEFAULT="--default-item $1"
102 _genericListBox --menu "$@"
105 ## a menu box with additional help info displayed
106 ## at the bottom of the window when an item is selected
109 _genericListBox --menu "$@"
115 ## a menu box with an addition button 'help'
118 _genericListBox --menu "$@"
125 _genericListBox --checklist "$@"
129 _genericListBox --radiolist "$@"
133 $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH
137 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
140 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
141 --passwordbox "$2" $HEIGHT $WIDTH 2> $temp
143 [ $status = 0 ] && REPLY=$(cat $temp)
149 #########################################################
150 ## begin-item-display style lists
152 ## these lists are built by calling fuctions multiple times.
153 ## this can make it easier to build your list in a loop
166 _menu_labels[$_menu_items]=$1
167 _menu_text[$_menu_items]=$2
168 _menu_status[$_menu_items]=$3 # available only for checklist
169 let "_menu_items += 1"
175 ## menu, checklist, radiolist
179 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
186 echo -ne " $HELP $_DEFAULT "
187 echo -ne " --backtitle '$BACKTITLE' "
188 echo -ne " --title '$_menu_title' "
189 echo -ne " --$boxtype '$_menu_msg' "
190 echo -ne " $HEIGHT $WIDTH 10 "
191 for ((i=0; i < $_menu_items ; i++)); do
192 label=${_menu_labels[$i]}
193 text=${_menu_text[$i]}
194 status=${_menu_status[$i]}
195 echo -ne " $label '$text' $status "
197 ) | xargs $DIALOG 2> $temp
201 [ $status = 0 ] && REPLY=`cat $temp`
207 ####################################################
219 _form_labels[$_form_items]=$1
220 _form_text[$_form_items]=$2
221 let "_form_items += 1"
225 local temp=$(@MKTEMP@ -t backupninja.XXXXXX) || exit 1
228 for ((i=0; i < ${#_form_labels[@]} ; i++)); do
229 label=${_form_labels[$i]}
230 length=`expr length $label`
231 if [ $length -gt $max_length ]; then
235 let "max_length += 2"
239 echo -n -e "--form '$_form_title' 0 0 20"
240 for ((i=0; i < $_form_items ; i++)); do
241 label=${_form_labels[$i]}
242 text=${_form_text[$i]}
243 echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 100"
244 let "xpos += _form_gap"
246 ) | xargs $DIALOG 2> $temp
250 ## the exit status is meaningless, it is always 0.
251 ## i can't figure out how to get the exit status of dialog
252 ## if we do "dialog `arg code`" or "dialog $args", then the quotes
253 ## get messed up and dialog won't run.
254 ## if we do "(arg code) | xargs dialog", then the exit status is
255 ## swallowed by xargs. xargs should return different exit status
256 ## depending on the exit status of the command run, but i have
257 ## never been able to get that to work.
261 if [ $status = 0 ]; then