From 373aa5232d0043556e802e93d9f70bec70f121c7 Mon Sep 17 00:00:00 2001 From: dteske Date: Sun, 2 Jun 2013 09:02:12 +0000 Subject: 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. --- usr.sbin/bsdconfig/console/console | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'usr.sbin/bsdconfig/console') 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 } -- cgit v1.1