3 # copyright 2002 lmoore@tump.com under the terms of the GNU LGPL.
5 # whiptail has trouble being called in the foo=$(whiptail ...) fashion for
6 # some reason. this is very annoying. this means that we need to use
7 # temporary files to store the answers from the input and list based boxes
8 # and then read the answers into a REPLY variable. that just really
9 # stinks, oh well, that's what you get when you have a weak link
12 # inputBox and passwordBox could be refactored to use a common function
14 test -z "$WIDTH" && WIDTH=0
15 test -z "$HEIGHT" && HEIGHT=0
20 setApplicationTitle() {
34 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
35 --yesno "$2" $HEIGHT $WIDTH
39 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
40 --msgbox "$2" $HEIGHT $WIDTH
44 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
45 --gauge "$2" $HEIGHT $WIDTH 0
49 local temp=$(mktemp -t) || exit 1
52 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
53 --inputbox "$2" $HEIGHT $WIDTH "$3" 2> $temp
55 [ $status = 0 ] && REPLY=$(cat $temp)
60 # Xdialog and {dialog,whiptail} use different mechanism to "qoute" the
61 # values from a checklist. {dialog,whiptail} uses standard double quoting
62 # while Xdialog uses a "/" as the separator. the slash is arguably better,
63 # but the double quoting is more standard. anyway, this function can be
64 # overridden to allow a derived implementation to change it's quoting
65 # mechanism to the standard double-quoting one. it receives two
66 # arguements, the file that has the data and the box type.
71 # this is the base implementation of all the list based boxes, it works
72 # out nicely that way. the real function just passes it's arguments to
73 # this function with an extra argument specifying the actual box that
74 # needs to be rendered.
81 local temp=$(mktemp -t) || exit 1
84 $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \
85 $box "$text" $HEIGHT $WIDTH 10 \
88 [ $status = 0 ] && REPLY=$(_listReplyHook $temp $box)
95 _DEFAULT="--default-item $1"
99 _genericListBox --menu "$@"
104 _genericListBox --menu "$@"
112 _genericListBox --menu "$@"
120 _genericListBox --checklist "$@"
124 _genericListBox --radiolist "$@"
128 $DIALOG --backtitle "$BACKTITLE" --title "$1" --textbox "$2" $HEIGHT $WIDTH
132 local temp=$(mktemp -t) || exit 1
135 $DIALOG --backtitle "$BACKTITLE" --title "$1" \
136 --passwordbox "$2" $HEIGHT $WIDTH 2> $temp
138 [ $status = 0 ] && REPLY=$(cat $temp)
152 _form_labels[$_form_items]=$1
153 _form_text[$_form_items]=$2
154 let "_form_items += 1"
158 local temp=$(mktemp -t) || exit 1
161 for ((i=0; i < ${#_form_labels[@]} ; i++)); do
162 label=${_form_labels[$i]}
163 length=`expr length $label`
164 if [ $length -gt $max_length ]; then
168 let "max_length += 2"
173 echo -n -e "--form '$_form_title' 0 0 20"
174 for ((i=0; i < $_form_items ; i++)); do
175 label=${_form_labels[$i]}
176 text=${_form_text[$i]}
177 # if [ "$text" == "" ]; then
180 echo -n -e "$form $label $xpos 1 '$text' $xpos $max_length 30 30"
181 let "xpos += _form_gap"
183 ) | xargs $DIALOG 2> $temp
185 [ $status = 0 ] && REPLY=`cat $temp`