diff options
author | dteske <dteske@FreeBSD.org> | 2012-10-26 00:31:25 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2012-10-26 00:31:25 +0000 |
commit | 28676bbae2f5bf85b90dc00212fdeebf6a374f53 (patch) | |
tree | c1df930faaba7fda6497c0525004a2e1ff99ac0d /usr.sbin | |
parent | af24b41220e9050f629345994d8049991ba4d117 (diff) | |
download | FreeBSD-src-28676bbae2f5bf85b90dc00212fdeebf6a374f53.zip FreeBSD-src-28676bbae2f5bf85b90dc00212fdeebf6a374f53.tar.gz |
Switch from using a msgbox to display help files to a textbox instead. The
problem with using a msgbox was one of truncation in the case of Xdialog(1)
and lack of screen real-estate (since the msgbox is not scrollable in X11
while a textbox is).
The textbox renders the text much better and is more appropriate for this
type of data display.
Approved by: adrian (co-mentor) (implicit)
Diffstat (limited to 'usr.sbin')
-rwxr-xr-x | usr.sbin/bsdconfig/bsdconfig | 9 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/security/kern_securelevel | 5 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/common.subr | 65 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/dialog.subr | 42 |
4 files changed, 81 insertions, 40 deletions
diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig index 5684c49..f80e5a9 100755 --- a/usr.sbin/bsdconfig/bsdconfig +++ b/usr.sbin/bsdconfig/bsdconfig @@ -37,8 +37,9 @@ f_include $BSDCFG_SHARE/strings.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" f_include_lang $BSDCFG_LIBE/include/messages.subr -f_include_help BSDCONFIG $BSDCFG_LIBE/include/bsdconfig.hlp -f_include_help USAGE $BSDCFG_LIBE/include/usage.hlp + +BSDCONFIG_HELPFILE=$BSDCFG_LIBE/include/bsdconfig.hlp +USAGE_HELPFILE=$BSDCFG_LIBE/include/usage.hlp ############################################################ FUNCTIONS @@ -302,7 +303,7 @@ while :; do if [ $retval -eq 2 ]; then # The Help button was pressed - f_show_msg "%s" "$( f_include_help BSDCONFIG )" + f_show_help "$BSDCONFIG_HELPFILE" continue elif [ $retval -ne 0 ]; then f_die @@ -314,7 +315,7 @@ while :; do ;; 1) # Usage - f_show_msg "%s" "$( f_include_help USAGE )" + f_show_help "$USAGE_HELPFILE" continue ;; diff --git a/usr.sbin/bsdconfig/security/kern_securelevel b/usr.sbin/bsdconfig/security/kern_securelevel index a0a7a95..1bb89d8 100755 --- a/usr.sbin/bsdconfig/security/kern_securelevel +++ b/usr.sbin/bsdconfig/security/kern_securelevel @@ -36,7 +36,8 @@ f_include $BSDCFG_SHARE/sysrc.subr BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="130.security" f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr -f_include_help SECURELEVEL $BSDCFG_LIBE/$APP_DIR/include/securelevel.hlp + +SECURELEVEL_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/securelevel.hlp ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) [ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" @@ -119,7 +120,7 @@ while :; do if [ $retval -eq 2 ]; then # The Help button was pressed - f_show_msg "%s" "$( f_include_help SECURELEVEL )" + f_show_help "$SECURELEVEL_HELPFILE" continue elif [ $retval -ne 0 ]; then f_die diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr index 11fc038..46fdc6f 100644 --- a/usr.sbin/bsdconfig/share/common.subr +++ b/usr.sbin/bsdconfig/share/common.subr @@ -140,6 +140,37 @@ f_show_msg() fi } +# f_show_help $file +# +# Display a language help-file. Automatically takes $LANG and $LC_ALL into +# consideration when displaying $file (suffix ".$LC_ALL" or ".$LANG" will +# automatically be added prior to loading the language help-file). +# +# If a language has been requested by setting either $LANG or $LC_ALL in the +# environment and the language-specific help-file does not exist we will fall +# back to $file without-suffix. +# +# If the language help-file does not exist, an error is displayed instead. +# +f_show_help() +{ + local file="$1" + local lang="${LANG:-$LC_ALL}" + + [ -f "$file.$lang" ] && file="$file.$lang" + + # + # Use f_dialog_textbox from dialog.subr if possible, otherwise fall + # back to dialog(1) (without options, making it obvious when using + # un-aided system dialog). + # + if f_have f_dialog_textbox; then + f_dialog_textbox "$file" + else + dialog --msgbox "$( cat "$file" 2>&1 )" 0 0 + fi +} + # f_include $file # # Include a shell subroutine file. @@ -179,40 +210,6 @@ f_include_lang() fi } -# f_include_help NAME [$file] -# -# When given both arguments, cache the contents of a language help-file to -# later be retrieved by executing again with only the first argument. -# -# Automatically takes $LANG and $LC_ALL into consideration when reading $file -# (suffix ".$LC_ALL" or ".$LANG" will automatically be added prior to loading -# the language help-file). -# -# If a language has been requested by setting either $LANG or $LC_ALL in the -# environment and the language-specific help-file does not exist we will fall -# back to $file without-suffix. -# -# If the language help-file does not exist, an error is cached in place of the -# help-file contents. -# -f_include_help() -{ - local name="$1" file="$2" - - if [ "$file" ]; then - local lang="${LANG:-$LC_ALL}" - - f_dprintf "name=[$name] lang=[$lang]" - if [ -f "$file.$lang" ]; then - setvar HELP_${name}_$$ "$( cat "$file.$lang" 2>&1 )" - else - setvar HELP_${name}_$$ "$( cat "$file" 2>&1 )" - fi - else - eval echo \"\$HELP_${name}_$$\" - fi -} - # f_usage $file [ $key1 $value1 ... ] # # Display USAGE file with optional pre-processor macro definitions. The first diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr index d2ba529..bd0fe2d 100644 --- a/usr.sbin/bsdconfig/share/dialog.subr +++ b/usr.sbin/bsdconfig/share/dialog.subr @@ -1015,6 +1015,48 @@ f_dialog_msgbox() --msgbox \"\$msg_text\" $size } +############################################################ TEXTBOX FUNCTIONS + +# f_dialog_textbox $file +# +# Display the contents of $file (or an error if $file does not exist, etc.) in +# a dialog(1) textbox (which has a scrollable region for the text). The textbox +# remains until the user presses ENTER or ESC, acknowledging the modal dialog. +# +# If the user presses ENTER, the exit status is zero (success), otherwise if +# the user presses ESC the exit status is 255. +# +f_dialog_textbox() +{ + [ "$DIALOG_SELF_INITIALIZE" ] && f_dialog_init + + local file="$1" + local contents retval size + + contents=$( cat "$file" 2>&1 ) + retval=$? + + size=$( f_dialog_buttonbox_size \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$contents" ) + + if [ $retval -eq $SUCCESS ]; then + eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --exit-label \"\$msg_ok\" \ + --no-cancel \ + --textbox \"\$file\" $size + else + eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --ok-label \"\$msg_ok\" \ + --msgbox \"\$msg_text\" $size + fi +} + ############################################################ YESNO FUNCTIONS # f_dialog_yesno $msg_text ... |