diff options
author | dteske <dteske@FreeBSD.org> | 2013-06-02 09:02:12 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-06-02 09:02:12 +0000 |
commit | 373aa5232d0043556e802e93d9f70bec70f121c7 (patch) | |
tree | 826a3cea2f1f978a5386dfa3b219f0c60dccae42 /usr.sbin/bsdconfig | |
parent | 5b05f067655217732e94ad77b1c57a3cb7a3945e (diff) | |
download | FreeBSD-src-373aa5232d0043556e802e93d9f70bec70f121c7.zip FreeBSD-src-373aa5232d0043556e802e93d9f70bec70f121c7.tar.gz |
Improve the dialog(1) API in dialog.subr by adding f_dialog_default_store()
and f_dialog_default_fetch(). Operating similar to functions introduced by
SVN r251236 and r251242, these functions operate as a pair for helping track
the default-item data (for the --menu, --checklist, and --radiolist
widgets).
This replaces the direct usage of a global to store the data with an
abstract method for readability and to centralize the code.
Diffstat (limited to 'usr.sbin/bsdconfig')
-rwxr-xr-x | usr.sbin/bsdconfig/bsdconfig | 8 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/console/console | 24 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/mouse/mouse | 24 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/networking/networking | 24 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/security/security | 4 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/dialog.subr | 39 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/misc | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcconf | 30 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcdelete | 32 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/rcvar | 28 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/startup/startup | 24 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/timezone/timezone | 22 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/groupinput | 21 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/userinput | 21 | ||||
-rwxr-xr-x | usr.sbin/bsdconfig/usermgmt/usermgmt | 28 |
15 files changed, 207 insertions, 126 deletions
diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig index 0cdda92..c65c6c2a 100755 --- a/usr.sbin/bsdconfig/bsdconfig +++ b/usr.sbin/bsdconfig/bsdconfig @@ -146,6 +146,7 @@ dialog_menu_main() local btitle="$DIALOG_BACKTITLE" local prompt="$msg_menu_text" local menu_list + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' '$msg_exit_bsdconfig' @@ -187,6 +188,9 @@ dialog_menu_main() \"\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ --clear \ @@ -198,7 +202,7 @@ dialog_menu_main() --help-button \ --help-label \"\$msg_help\" \ ${USE_XDIALOG:+--help \"\"} \ - --default-item \"\$DEFAULTITEM_$$\" \ + --default-item \"\$defaultitem\" \ --menu \"\$prompt\" \ $height $width $rows \ $menu_list \ @@ -209,7 +213,7 @@ dialog_menu_main() f_dialog_menutag_store "$menu_choice" # Only update default-item on success - [ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/console/console b/usr.sbin/bsdconfig/console/console index 630d071..6fe5bab 100755 --- a/usr.sbin/bsdconfig/console/console +++ b/usr.sbin/bsdconfig/console/console @@ -51,6 +51,7 @@ dialog_menu_main() local menu_list local hline="$hline_configure_system_console_settings" local prompt="$msg_console_menu_text" + local defaultitem= # Calculated below menu_list=" 'X $msg_exit' '$msg_exit_this_menu' @@ -70,23 +71,26 @@ dialog_menu_main() \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/mouse/mouse b/usr.sbin/bsdconfig/mouse/mouse index 8a8f125..cfc91ce 100755 --- a/usr.sbin/bsdconfig/mouse/mouse +++ b/usr.sbin/bsdconfig/mouse/mouse @@ -51,6 +51,7 @@ dialog_menu_main() local menu_list local hline="" local prompt="$msg_menu_text" + local defaultitem= # Calculated below menu_list=" 'X $msg_exit' '$msg_exit_this_menu' @@ -69,23 +70,26 @@ dialog_menu_main() \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/networking/networking b/usr.sbin/bsdconfig/networking/networking index 13d5018..e1d30cf 100755 --- a/usr.sbin/bsdconfig/networking/networking +++ b/usr.sbin/bsdconfig/networking/networking @@ -50,6 +50,7 @@ dialog_menu_main() { local menu_list local hline="$hline_arrows_tab_enter" + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' @@ -67,23 +68,26 @@ dialog_menu_main() \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/security/security b/usr.sbin/bsdconfig/security/security index eb7a73d..5ad6f88 100755 --- a/usr.sbin/bsdconfig/security/security +++ b/usr.sbin/bsdconfig/security/security @@ -54,7 +54,7 @@ dialog_menu_main() local prompt="$msg_menu_text" # Obtain default-item (adjusted below for dynamic tags) - f_getvar DEFAULTITEM_$$ defaultitem + f_dialog_default_fetch defaultitem local ditem="${defaultitem%%[$IFS]*}" menu_list=" @@ -123,7 +123,7 @@ dialog_menu_main() f_dialog_menutag_store "$menu_choice" # Only update default-item on success - [ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr index 2b65d31..2c81333 100644 --- a/usr.sbin/bsdconfig/share/dialog.subr +++ b/usr.sbin/bsdconfig/share/dialog.subr @@ -1757,6 +1757,45 @@ f_dialog_menutag_fetch() return $SUCCESS } +# f_dialog_default_store [-s] $text +# +# Store some text to be used later as the --default-item argument to dialog(1) +# (or Xdialog(1)) for --menu, --checklist, and --radiolist widgets. Retrieve +# the text later with f_dialog_menutag_fetch(). If the first argument is `-s', +# the text is sanitized before being stored. +# +f_dialog_default_store() +{ + local sanitize= + [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s + local text="$1" + + # Sanitize the defaulitem before storing it if desired + [ "$sanitize" ] && f_dialog_data_sanitize text + + setvar DEFAULTITEM_$$ "$text" +} + +# f_dialog_default_fetch [$var_to_set] +# +# Obtain text to be used with the --default-item argument of dialog(1) (or +# Xdialog(1)) (previously stored with f_dialog_default_store() above). If +# $var_to_set is NULL or missing, output is printed to stdout (which is less +# recommended due to performance degradation; in a loop for example). +# +f_dialog_default_fetch() +{ + local __var_to_set="$1" __cp + + debug= f_getvar DEFAULTITEM_$$ "${__var_to_set:-__cp}" # get the data + setvar DEFAULTITEM_$$ "" # scrub memory in case data was sensitive + + # Return the data on standard-out if desired + [ "$__var_to_set" ] || echo "$__cp" + + return $SUCCESS +} + # f_dialog_menutag2item $tag_chosen $tag1 $item1 $tag2 $item2 ... # # To use the `--menu' option of dialog(1) you must pass an ordered list of diff --git a/usr.sbin/bsdconfig/startup/misc b/usr.sbin/bsdconfig/startup/misc index 6e33462..01c0a4c 100755 --- a/usr.sbin/bsdconfig/startup/misc +++ b/usr.sbin/bsdconfig/startup/misc @@ -61,7 +61,7 @@ dialog_menu_main() local prompt="$msg_miscellaneous_menu_text" # Obtain default-item (adjusted below for dynamic tags) - f_getvar DEFAULTITEM_$$ defaultitem + f_dialog_default_fetch defaultitem local ditem="${defaultitem%%[$IFS]*}" menu_list=" @@ -289,7 +289,7 @@ dialog_menu_main() local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/startup/rcconf b/usr.sbin/bsdconfig/startup/rcconf index 5a97b4e..3b84531 100755 --- a/usr.sbin/bsdconfig/startup/rcconf +++ b/usr.sbin/bsdconfig/startup/rcconf @@ -81,6 +81,7 @@ dialog_menu_main() { local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below RCCONF_MENU_LIST=" 'X $msg_exit' '$msg_exit_desc' @@ -170,20 +171,23 @@ dialog_menu_main() \"\$hline\" \ $RCCONF_MENU_LIST + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --help-button \ - --help-label \"\$msg_details\" \ - ${SHOW_DESC:+--item-help} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $RCCONF_MENU_LIST \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_details\" \ + ${SHOW_DESC:+--item-help} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $RCCONF_MENU_LIST \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? @@ -191,7 +195,7 @@ dialog_menu_main() f_dialog_menutag_store "$menu_choice" # Only update default-item on success - [ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/startup/rcdelete b/usr.sbin/bsdconfig/startup/rcdelete index 166b0e1..db935eb 100755 --- a/usr.sbin/bsdconfig/startup/rcdelete +++ b/usr.sbin/bsdconfig/startup/rcdelete @@ -148,6 +148,7 @@ dialog_menu_main() { local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below # # [Re-]Accent the menu list before incorporating it @@ -205,21 +206,24 @@ dialog_menu_main() \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --keep-tite \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --help-button \ - --help-label \"\$msg_details\" \ - ${SHOW_DESC:+--item-help} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --keep-tite \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_details\" \ + ${SHOW_DESC:+--item-help} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? @@ -227,7 +231,7 @@ dialog_menu_main() f_dialog_menutag_store "$menu_choice" # Only update default-item on success - [ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/startup/rcvar b/usr.sbin/bsdconfig/startup/rcvar index f8f8f0e..67748dd 100755 --- a/usr.sbin/bsdconfig/startup/rcvar +++ b/usr.sbin/bsdconfig/startup/rcvar @@ -67,6 +67,7 @@ dialog_menu_main() { local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below RCVAR_MENU_LIST=" 'X $msg_exit' '$msg_exit_this_menu' @@ -134,25 +135,28 @@ dialog_menu_main() \"\$hline\" \ $RCVAR_MENU_LIST + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --keep-tite \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - ${SHOW_DESC:+--item-help} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $RCVAR_MENU_LIST \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --keep-tite \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + ${SHOW_DESC:+--item-help} \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $RCVAR_MENU_LIST \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/startup/startup b/usr.sbin/bsdconfig/startup/startup index d24822a..15bd66a 100755 --- a/usr.sbin/bsdconfig/startup/startup +++ b/usr.sbin/bsdconfig/startup/startup @@ -51,6 +51,7 @@ dialog_menu_main() local menu_list local hline="$hline_arrows_tab_enter" local prompt="" + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' @@ -67,23 +68,26 @@ dialog_menu_main() \"\$hline\" \ $menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $menu_list \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/timezone/timezone b/usr.sbin/bsdconfig/timezone/timezone index 89e8c7f..44bba7c 100755 --- a/usr.sbin/bsdconfig/timezone/timezone +++ b/usr.sbin/bsdconfig/timezone/timezone @@ -83,6 +83,7 @@ dialog_menu_main() local title="$DIALOG_TITLE" local btitle="$DIALOG_BACKTITLE" local prompt="$msg_select_region" + local defaultitem= # Calculated below local height width rows eval f_dialog_menu_size height width rows \ @@ -92,22 +93,25 @@ dialog_menu_main() \"\" \ $continent_menu_list + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" \ - $height $width $rows \ - $continent_menu_list \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$prompt\" \ + $height $width $rows \ + $continent_menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? f_dialog_data_sanitize menu_choice f_dialog_menutag_store "$menu_choice" - setvar DEFAULTITEM_$$ "$menu_choice" + f_dialog_default_store "$menu_choice" return $retval } diff --git a/usr.sbin/bsdconfig/usermgmt/groupinput b/usr.sbin/bsdconfig/usermgmt/groupinput index f1c8d68..ac27c98 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupinput +++ b/usr.sbin/bsdconfig/usermgmt/groupinput @@ -228,21 +228,22 @@ while :; do \"\$hline\" \ $menu_items + f_dialog_default_fetch defaultitem mtag=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$menu_text\" \ - $height $width $rows \ - $menu_items \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$menu_text\" \ + $height $width $rows \ + $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? f_dialog_data_sanitize mtag - setvar DEFAULTITEM_$$ "$mtag" + f_dialog_default_store "$mtag" f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No diff --git a/usr.sbin/bsdconfig/usermgmt/userinput b/usr.sbin/bsdconfig/usermgmt/userinput index 7df1993..df79ac5 100755 --- a/usr.sbin/bsdconfig/usermgmt/userinput +++ b/usr.sbin/bsdconfig/usermgmt/userinput @@ -391,21 +391,22 @@ while :; do \"\$hline\" \ $menu_items + f_dialog_default_fetch defaultitem mtag=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$menu_text\" \ - $height $width $rows \ - $menu_items \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --default-item \"\$defaultitem\" \ + --menu \"\$menu_text\" \ + $height $width $rows \ + $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? f_dialog_data_sanitize mtag - setvar DEFAULTITEM_$$ "$mtag" + f_dialog_default_store "$mtag" f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" # Exit if user has either pressed ESC or chosen Cancel/No diff --git a/usr.sbin/bsdconfig/usermgmt/usermgmt b/usr.sbin/bsdconfig/usermgmt/usermgmt index e91b44c..880985f 100755 --- a/usr.sbin/bsdconfig/usermgmt/usermgmt +++ b/usr.sbin/bsdconfig/usermgmt/usermgmt @@ -53,6 +53,7 @@ dialog_menu_main() { local menu_list local hline="$hline_arrows_tab_enter" + local defaultitem= # Calculated below menu_list=" 'X' '$msg_exit' @@ -76,20 +77,23 @@ dialog_menu_main() # When using Xdialog(1) we need to bump the width for the buttons [ "$USE_XDIALOG" ] && width=40 + # Obtain default-item from previously stored selection + f_dialog_default_fetch defaultitem + local menu_choice menu_choice=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --help-button \ - --help-label \"\$msg_help\" \ - ${USE_XDIALOG:+--help \"\"} \ - --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\" \ - $height $width $rows \ - $menu_list \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_help\" \ + ${USE_XDIALOG:+--help \"\"} \ + --default-item \"\$defaultitem\" \ + --menu \"\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? @@ -97,7 +101,7 @@ dialog_menu_main() f_dialog_menutag_store "$menu_choice" # Only update default-item on success - [ $retval -eq 0 ] && setvar DEFAULTITEM_$$ "$menu_choice" + [ $retval -eq 0 ] && f_dialog_default_store "$menu_choice" return $retval } |