summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2012-12-21 18:58:19 +0000
committerdteske <dteske@FreeBSD.org>2012-12-21 18:58:19 +0000
commit5e7ea05b1afc71ededb3af74c2ab29cec62cc286 (patch)
treeb36ed1ce72c48c84674686128b0f6e806b3330e4 /usr.sbin/bsdconfig/share
parent804c67a4867afb8b7ef41a3ade748cab870b788c (diff)
downloadFreeBSD-src-5e7ea05b1afc71ededb3af74c2ab29cec62cc286.zip
FreeBSD-src-5e7ea05b1afc71ededb3af74c2ab29cec62cc286.tar.gz
Add much-needed dialog(1) --inputbox function for simplifying the process of
requesting input from the user.
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r--usr.sbin/bsdconfig/share/dialog.subr50
1 files changed, 48 insertions, 2 deletions
diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr
index bf10388..4f45817 100644
--- a/usr.sbin/bsdconfig/share/dialog.subr
+++ b/usr.sbin/bsdconfig/share/dialog.subr
@@ -1115,7 +1115,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 +1138,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()
{
OpenPOWER on IntegriCloud