#!/bin/bash
# copyright 2002 lmoore@tump.com under the terms of the GNU LGPL.
+# additions 2005 collective@riseup.net
# whiptail has trouble being called in the foo=$(whiptail ...) fashion for
# some reason. this is very annoying. this means that we need to use
}
setHelp() {
- HELP="$@"
+ HELP="$@"
}
setDimension() {
local temp=$(mktemp -t) || exit 1
trap "rm -f $temp" 0
REPLY=
- $DIALOG $HELP --backtitle "$BACKTITLE" --title "$title" \
+ $DIALOG $HELP $_DEFAULT --backtitle "$BACKTITLE" --title "$title" \
$box "$text" $HEIGHT $WIDTH 10 \
"$@" 2> $temp
local status=$?
[ $status = 0 ] && REPLY=$(_listReplyHook $temp $box)
rm -f $temp
+ _DEFAULT=
return $status
}
+setDefault() {
+ _DEFAULT="--default-item $1"
+}
+
menuBox() {
_genericListBox --menu "$@"
}
+## a menu box with additional help info displayed
+## at the bottom of the window when an item is selected
menuBoxHelp() {
HELP="--item-help"
_genericListBox --menu "$@"
return $status
}
+## a menu box with an addition button 'help'
menuBoxHelpFile() {
HELP="--help-button"
_genericListBox --menu "$@"
return $status
}
-
checkBox() {
_genericListBox --checklist "$@"
}
return $status
}
+
+#########################################################
+## begin-item-display style lists
+##
+## these lists are built by calling fuctions multiple times.
+## this can make it easier to build your list in a loop
+##
+
+listBegin() {
+ _menu_title=$1
+ _menu_msg=$2
+ _menu_items=0
+ _menu_text=
+ _menu_labels=
+}
+
+listItem() {
+ _menu_labels[$_menu_items]=$1
+ _menu_text[$_menu_items]=$2
+ let "_menu_items += 1"
+}
+
+
+##
+## takes one of:
+## menu, checklist, radiolist
+##
+listDisplay() {
+ boxtype=$1
+ local temp=$(mktemp -t) || exit 1
+ trap "rm -f $temp" 0
+
+ (
+ echo -ne " $HELP $_DEFAULT "
+ echo -ne " --backtitle '$BACKTITLE' "
+ echo -ne " --title '$_menu_title' "
+ echo -ne " --$boxtype '$_menu_msg' "
+ echo -ne " $HEIGHT $WIDTH 10 "
+ for ((i=0; i < $_menu_items ; i++)); do
+ label=${_menu_labels[$i]}
+ text=${_menu_text[$i]}
+ echo -ne " $label '$text' "
+ done
+ ) | xargs $DIALOG 2> $temp
+
+ local status=$?
+ REPLY=""
+ [ $status = 0 ] && REPLY=`cat $temp`
+ rm -f $temp
+ _DEFAULT=
+ return $status
+}
+
+####################################################
+## FORM
+
_form_gap=2
-startForm() {
+formBegin() {
_form_title=$1
_form_items=0
_form_labels=
let "_form_items += 1"
}
-displayForm() {
+formDisplay() {
local temp=$(mktemp -t) || exit 1
max_length=0
done
let "max_length += 2"
- local form=
local xpos=1
- for ((i=0; i < $_form_items ; i++)); do
- label=${_form_labels[$i]}
- text=${_form_text[$i]}
- if [ "$text" == "" ]; then
- text='_empty_'
- fi
- form=`echo -e "$form $label $xpos 1" $text "$xpos $max_length 30 30"`
- let "xpos += _form_gap"
- done
-
- $DIALOG --form "$_form_title" 0 0 20 $form 2> $temp
+ (
+ echo -n -e "--form '$_form_title' 0 0 20"
+ for ((i=0; i < $_form_items ; i++)); do
+ label=${_form_labels[$i]}
+ text=${_form_text[$i]}
+ echo -n -e " $label $xpos 1 '$text' $xpos $max_length 30 30"
+ let "xpos += _form_gap"
+ done
+ ) | xargs $DIALOG 2> $temp
local status=$?
- [ $status = 0 ] && REPLY=$(cat $temp)
+
+ if [ $status = 0 ]; then
+ IFS=$''
+ REPLY=`cat $temp`
+ IFS=$' \t\n'
+ fi
rm -f $temp
return $status
}