Author: dteske
Date: Fri Oct 26 00:31:25 2012
New Revision: 242107
URL: http://svn.freebsd.org/changeset/base/242107

Log:
  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)

Modified:
  head/usr.sbin/bsdconfig/bsdconfig
  head/usr.sbin/bsdconfig/security/kern_securelevel
  head/usr.sbin/bsdconfig/share/common.subr
  head/usr.sbin/bsdconfig/share/dialog.subr

Modified: head/usr.sbin/bsdconfig/bsdconfig
==============================================================================
--- head/usr.sbin/bsdconfig/bsdconfig   Fri Oct 26 00:30:44 2012        
(r242106)
+++ head/usr.sbin/bsdconfig/bsdconfig   Fri Oct 26 00:31:25 2012        
(r242107)
@@ -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
           ;;
 

Modified: head/usr.sbin/bsdconfig/security/kern_securelevel
==============================================================================
--- head/usr.sbin/bsdconfig/security/kern_securelevel   Fri Oct 26 00:30:44 
2012        (r242106)
+++ head/usr.sbin/bsdconfig/security/kern_securelevel   Fri Oct 26 00:31:25 
2012        (r242107)
@@ -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

Modified: head/usr.sbin/bsdconfig/share/common.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/common.subr   Fri Oct 26 00:30:44 2012        
(r242106)
+++ head/usr.sbin/bsdconfig/share/common.subr   Fri Oct 26 00:31:25 2012        
(r242107)
@@ -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

Modified: head/usr.sbin/bsdconfig/share/dialog.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/dialog.subr   Fri Oct 26 00:30:44 2012        
(r242106)
+++ head/usr.sbin/bsdconfig/share/dialog.subr   Fri Oct 26 00:31:25 2012        
(r242107)
@@ -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 ...
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to