3 # copyright 2002 lmoore@tump.com under the terms of the GNU LGPL.
4 # additions 2005 collective@riseup.net
6 # whiptail has trouble being called in the foo=$(whiptail ...) fashion for
7 # some reason. this is very annoying. this means that we need to use
8 # temporary files to store the answers from the input and list based boxes
9 # and then read the answers into a REPLY variable. that just really
10 # stinks, oh well, that's what you get when you have a weak link
13 # inputBox and passwordBox could be refactored to use a common function
15 test -z "$WIDTH" && WIDTH=0
16 test -z "$HEIGHT" && HEIGHT=0
21 setApplicationTitle() {
35 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
36 --yesno "$2" $HEIGHT $WIDTH
40 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
41 --msgbox "$2" $HEIGHT $WIDTH
45 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
46 --gauge "$2" $HEIGHT $WIDTH 0
50 local temp=$(mktemp -t) || exit 1
53 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
54 --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp
56 [ $status = 0 ] && REPLY=$(cat $temp)
61 # Xdialog and {dialog,whiptail} use different mechanism to "qoute" the
62 # values from a checklist. {dialog,whiptail} uses standard double quoting
63 # while Xdialog uses a "/" as the separator. the slash is arguably better,
64 # but the double quoting is more standard. anyway, this function can be
65 # overridden to allow a derived implementation to change it's quoting
66 # mechanism to the standard double-quoting one. it receives two
67 # arguements, the file that has the data and the box type.
72 # this is the base implementation of all the list based boxes, it works
73 # out nicely that way. the real function just passes it's arguments to
74 # this function with an extra argument specifying the actual box that
75 # needs to be rendered.
82 local temp=$(mktemp -t) || exit 1
85 $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \
86 $box "$text" $HEIGHT $WIDTH 10 \
89 [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box)
96 _DEFAULT="--default-item $1"
100 _genericListBox --menu "$@"
103 ## a menu box with additional help info displayed
104 ## at the bottom of the window when an item is selected
107 _genericListBox --menu "$@"
113 ## a menu box with an addition button 'help'
116 _genericListBox --menu "$@"
123 _genericListBox --checklist "$@"
127 _genericListBox --radiolist "$@"
131 $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH
135 local temp=$(mktemp -t) || exit 1
138 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
139 --passwordbox "$2" $HEIGHT $WIDTH 2> $temp
141 [ $status = 0 ] && REPLY=$(cat $temp)
147 #########################################################
148 ## begin-item-display style lists
150 ## these lists are built by calling fuctions multiple times.
151 ## this can make it easier to build your list in a loop
163 _menu_labels[$_menu_items]=$1
164 _menu_text[$_menu_items]=$2
165 let "_menu_items += 1"
171 ## menu, checklist, radiolist
175 local temp=$(mktemp -t) || exit 1
179 echo -ne " $HELP $_DEFAULT "
180 echo -ne " --backtitle '$BACKTITLE' "
181 echo -ne " --title '$_menu_title' "
182 echo -ne " --$boxtype '$_menu_msg' "
183 echo -ne " $HEIGHT $WIDTH 10 "
184 for ((i=0; i < $_menu_items ; i++)); do
185 label=${_menu_labels[$i]}
186 text=${_menu_text[$i]}
187 echo -ne " $label '$text' "
189 ) | xargs $DIALOG 2> $temp
193 [ $status = 0 ] && REPLY=`cat $temp`
199 ####################################################
211 _form_labels[$_form_items]=$1
212 _form_text[$_form_items]=$2
213 let "_form_items += 1"
217 local temp=$(mktemp -t) || exit 1
220 for ((i=0; i < ${#_form_labels[@]} ; i++)); do
221 label=${_form_labels[$i]}
222 length=`expr length $label`
223 if [ $length -gt $max_length ]; then
227 let "max_length += 2"
231 echo -n -e "--form '$_form_title' 0 0 20"
232 for ((i=0; i < $_form_items ; i++)); do
233 label=${_form_labels[$i]}
234 text=${_form_text[$i]}
235 echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30"
236 let "xpos += _form_gap"
238 ) | xargs $DIALOG 2> $temp
241 if [ $status = 0 ]; then