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 `[ "$3" == no ] && echo '--defaultno'` --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
164 _menu_labels[$_menu_items]=$1
165 _menu_text[$_menu_items]=$2
166 _menu_status[$_menu_items]=$3 # available only for checklist
167 let "_menu_items += 1"
173 ## menu, checklist, radiolist
177 local temp=$(mktemp -t) || exit 1
184 echo -ne " $HELP $_DEFAULT "
185 echo -ne " --backtitle '$BACKTITLE' "
186 echo -ne " --title '$_menu_title' "
187 echo -ne " --$boxtype '$_menu_msg' "
188 echo -ne " $HEIGHT $WIDTH 10 "
189 for ((i=0; i < $_menu_items ; i++)); do
190 label=${_menu_labels[$i]}
191 text=${_menu_text[$i]}
192 status=${_menu_status[$i]}
193 echo -ne " $label '$text' $status "
195 ) | xargs $DIALOG 2> $temp
199 [ $status = 0 ] && REPLY=`cat $temp`
205 ####################################################
217 _form_labels[$_form_items]=$1
218 _form_text[$_form_items]=$2
219 let "_form_items += 1"
223 local temp=$(mktemp -t) || exit 1
226 for ((i=0; i < ${#_form_labels[@]} ; i++)); do
227 label=${_form_labels[$i]}
228 length=`expr length $label`
229 if [ $length -gt $max_length ]; then
233 let "max_length += 2"
237 echo -n -e "--form '$_form_title' 0 0 20"
238 for ((i=0; i < $_form_items ; i++)); do
239 label=${_form_labels[$i]}
240 text=${_form_text[$i]}
241 echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30"
242 let "xpos += _form_gap"
244 ) | xargs $DIALOG 2> $temp
248 if [ $status = 0 ]; then