summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share/dialog.subr
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bsdconfig/share/dialog.subr')
-rw-r--r--usr.sbin/bsdconfig/share/dialog.subr99
1 files changed, 86 insertions, 13 deletions
diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr
index bf10388..f614be2 100644
--- a/usr.sbin/bsdconfig/share/dialog.subr
+++ b/usr.sbin/bsdconfig/share/dialog.subr
@@ -30,6 +30,7 @@ if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
+f_dprintf "%s: loading includes..." dialog.subr
f_include $BSDCFG_SHARE/strings.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig"
@@ -42,7 +43,7 @@ f_include_lang $BSDCFG_LIBE/include/messages.subr
# execution of dialog from within a sub-shell (so-long as its standard output
# is explicitly redirected to this file descriptor).
#
-: ${DIALOG_TERMINAL_PASSTHRU_FD:=3}
+: ${DIALOG_TERMINAL_PASSTHRU_FD:=${TERMINAL_STDOUT_PASSTHRU:-3}}
############################################################ GLOBALS
@@ -76,6 +77,11 @@ unset XDIALOG_INFOBOX_TIMEOUT
#
: ${DIALOG_SELF_INITIALIZE=1}
+#
+# Default terminal size (used if/when running without a controlling terminal)
+#
+: ${DEFAULT_TERMINAL_SIZE:=24 80}
+
############################################################ GENERIC FUNCTIONS
# f_dialog_title [$new_title]
@@ -192,7 +198,8 @@ f_dialog_infobox_size()
max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
else
min_width=24
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_height="${max_size%%[$IFS]*}"
@@ -324,7 +331,8 @@ f_dialog_buttonbox_size()
if [ "$USE_XDIALOG" ]; then
max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
else
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_height="${max_size%%[$IFS]*}"
[ $height -le $max_height ] || height=$max_height
@@ -362,7 +370,8 @@ f_dialog_inputbox_size()
max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
else
min_width=24
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_height="${max_size%%[$IFS]*}"
local max_width="${max_size##*[$IFS]}"
@@ -471,6 +480,7 @@ f_xdialog_2inputsbox_size()
# Add height for a second inputbox
height=$(( $height + 2 ))
+ [ $height -le $max_height ] || height=$max_height
#
# Bump width for second initial text (if not already at maximum width).
@@ -520,7 +530,8 @@ f_dialog_menu_size()
else
min_width=24
min_rows=0
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_width="${max_size##*[$IFS]}"
@@ -602,7 +613,8 @@ f_dialog_menu_with_help_size()
else
min_width=24
min_rows=0
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_width="${max_size##*[$IFS]}"
@@ -701,7 +713,8 @@ f_dialog_radiolist_size()
else
min_width=24
min_rows=0
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_width="${max_size##*[$IFS]}"
@@ -787,7 +800,8 @@ f_dialog_calendar_size()
else
min_height=0
min_width=40
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_height="${max_size%%[$IFS]*}"
local max_width="${max_size##*[$IFS]}"
@@ -865,7 +879,8 @@ f_dialog_timebox_size()
else
min_height=0
min_width=20
- max_size=$( stty size ) # usually "24 80"
+ max_size=$( stty size 2> /dev/null ) # usually "24 80"
+ : ${max_size:=$DEFAULT_TERMINAL_SIZE}
fi
local max_height="${max_size%%[$IFS]*}"
local max_width="${max_size##*[$IFS]}"
@@ -923,7 +938,7 @@ f_dialog_clear()
# f_dialog_info $info_text ...
#
# Throw up a dialog(1) infobox. The infobox remains until another dialog is
-# displayed or `dialog --clear' (or dialog_clear) is called.
+# displayed or `dialog --clear' (or f_dialog_clear) is called.
#
f_dialog_info()
{
@@ -1115,7 +1130,7 @@ f_dialog_noyes()
# f_dialog_inputstr
#
# Obtain the inputstr entered by the user from the most recently displayed
-# dialog(1) inputbox and clean up any temporary files.
+# dialog(1) inputbox and clean up any temporary files/variables.
#
f_dialog_inputstr()
{
@@ -1138,12 +1153,58 @@ f_dialog_inputstr()
return $SUCCESS
}
+# f_dialog_input $prompt [$init [$hline]]
+#
+# Prompt the user with a dialog(1) inputbox to enter some value. The inputbox
+# remains until the the user presses ENTER or ESC, or otherwise ends the
+# editing session, by selecting `Cancel' for example.
+#
+# If the user presses ENTER, the exit status is zero (success), otherwise if
+# the user presses ESC the exit status is 255, or if the user chose Cancel, the
+# exit status is instead 1.
+#
+# NOTE: The hline should correspond to the type of data you want from the user.
+# NOTE: Should not be used to edit multiline values.
+#
+f_dialog_input()
+{
+ local prompt="$1" init="$2" hline="$3"
+ local size="$( f_dialog_inputbox_size \
+ "$DIALOG_TITLE" \
+ "$DIALOG_BACKTITLE" \
+ "$prompt" \
+ "$init" \
+ "$hline" )"
+
+ local opterm="--"
+ [ "$USE_XDIALOG" ] && opterm=
+
+ local dialog_input
+ dialog_input=$(
+ eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --inputbox \"\$prompt\" $size \
+ $opterm \"\$init\" \
+ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+ )
+ local retval=$?
+
+ setvar DIALOG_INPUTBOX_$$ "$dialog_input"
+ f_dialog_inputstr
+
+ return $retval
+}
+
############################################################ MENU FUNCTIONS
# f_dialog_menutag
#
# Obtain the menutag chosen by the user from the most recently displayed
-# dialog(1) menu and clean up any temporary files.
+# dialog(1) menu and clean up any temporary files/variables.
#
f_dialog_menutag()
{
@@ -1427,10 +1488,22 @@ f_dialog_init()
DIALOG_BACKTITLE="$_DIALOG_TITLE"
unset _DIALOG_TITLE
fi
+
+ f_dprintf "f_dialog_init: dialog(1) API initialized."
}
############################################################ MAIN
-[ "$DIALOG_SELF_INITIALIZE" ] && f_dialog_init
+#
+# Self-initialize unless requested otherwise
+#
+f_dprintf "%s: DIALOG_SELF_INITIALIZE=[%s]" \
+ dialog.subr "$DIALOG_SELF_INITIALIZE"
+case "$DIALOG_SELF_INITIALIZE" in
+""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;;
+*) f_dialog_init
+esac
+
+f_dprintf "%s: Successfully loaded." dialog.subr
fi # ! $_DIALOG_SUBR
OpenPOWER on IntegriCloud