diff options
author | dteske <dteske@FreeBSD.org> | 2013-05-31 19:07:17 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-05-31 19:07:17 +0000 |
commit | a0eece46063b1db33804c35b64793e3afc2424c1 (patch) | |
tree | 2634f68f77f7c057b30aa67f1c494a01df2e22a7 /usr.sbin/bsdconfig | |
parent | 838ba827a2bbb59d8184419cf6632b7afa203afa (diff) | |
download | FreeBSD-src-a0eece46063b1db33804c35b64793e3afc2424c1.zip FreeBSD-src-a0eece46063b1db33804c35b64793e3afc2424c1.tar.gz |
Improve portion of the dialog(1) API in dialog.subr responsible for
calculating widget sizes. Instead of forking a sub-shell to calculate the
optimum size for a widget, use a byRef style call-out to set variables in
the parent namespace. For example, instead of:
size=$( f_dialog_buttonbox_size title btitle msg )
$DIALOG --title title --backtitle btitle --msgbox msg $size
The new API replaces the above with the following:
f_dialog_buttonbox_size height width title btitle msg
$DIALOG --title title --backtitle btitle --msgbox msg $height $width
This reduces the number of forks, improves performance, and makes the code
more readable by revealing the argument-order for widget sizing. It also
makes performing minor adjustments to the calculated values easier as
you no longer have to split-out the response (which required knowledge of
ordering so was counter-intuitive).
Diffstat (limited to 'usr.sbin/bsdconfig')
38 files changed, 1743 insertions, 1368 deletions
diff --git a/usr.sbin/bsdconfig/bsdconfig b/usr.sbin/bsdconfig/bsdconfig index 90fcf86..890e797 100755 --- a/usr.sbin/bsdconfig/bsdconfig +++ b/usr.sbin/bsdconfig/bsdconfig @@ -145,7 +145,7 @@ dialog_menu_main() local title="$DIALOG_TITLE" local btitle="$DIALOG_BACKTITLE" local prompt="$msg_menu_text" - local menu_list size + local menu_list menu_list=" 'X' '$msg_exit' '$msg_exit_bsdconfig' @@ -179,12 +179,13 @@ dialog_menu_main() index=$(( $index + 1 )) done - size=$( eval f_dialog_menu_with_help_size \ - \"\$title\" \ - \"\$btitle\" \ - \"\$prompt\" \ - \"\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_with_help_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -198,7 +199,9 @@ dialog_menu_main() --help-label \"\$msg_help\" \ ${USE_XDIALOG:+--help \"\"} \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size $menu_list \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? diff --git a/usr.sbin/bsdconfig/console/console b/usr.sbin/bsdconfig/console/console index e4d978c..da71c73 100755 --- a/usr.sbin/bsdconfig/console/console +++ b/usr.sbin/bsdconfig/console/console @@ -48,7 +48,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size + local menu_list local hline="$hline_configure_system_console_settings" local prompt="$msg_console_menu_text" @@ -62,12 +62,13 @@ dialog_menu_main() '7 $msg_ttys' '$msg_choose_console_terminal_type' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -77,7 +78,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/console/font b/usr.sbin/bsdconfig/console/font index 57af2e8..101a374 100755 --- a/usr.sbin/bsdconfig/console/font +++ b/usr.sbin/bsdconfig/console/font @@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="$hline_choose_a_font" local prompt="$msg_font_menu_text" @@ -70,12 +70,13 @@ dialog_menu_main() 'e $msg_swiss' '$msg_swiss_desc' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get font8x8 )" in [Nn][Oo]|'') defaultitem="1 $msg_none";; @@ -102,7 +103,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/console/keymap b/usr.sbin/bsdconfig/console/keymap index e5f6462..aa51f7d 100755 --- a/usr.sbin/bsdconfig/console/keymap +++ b/usr.sbin/bsdconfig/console/keymap @@ -77,7 +77,7 @@ KEYMAP_NAMES=" # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="$hline_choose_a_keyboard_map" local prompt="$msg_keymap_menu_text" @@ -110,12 +110,13 @@ dialog_menu_main() }' ) - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get keymap )" in be.iso) defaultitem="$msg_belgian";; @@ -200,7 +201,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/console/repeat b/usr.sbin/bsdconfig/console/repeat index 5447315..85822e0 100755 --- a/usr.sbin/bsdconfig/console/repeat +++ b/usr.sbin/bsdconfig/console/repeat @@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="$hline_choose_a_keyboard_repeat_rate" local prompt="$msg_repeat_menu_text" @@ -60,12 +60,13 @@ dialog_menu_main() '$msg_fast' '$msg_fast_desc' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get keyrate )" in slow) defaultitem="$msg_slow";; @@ -82,7 +83,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/console/saver b/usr.sbin/bsdconfig/console/saver index fa3bffe..99cb81c 100755 --- a/usr.sbin/bsdconfig/console/saver +++ b/usr.sbin/bsdconfig/console/saver @@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="$hline_choose_a_screen_saver" local prompt="$msg_saver_menu_text" @@ -70,12 +70,13 @@ dialog_menu_main() '$msg_timeout' '$msg_timeout_desc' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get saver )" in blank) defaultitem="1 $msg_blank" ;; @@ -101,7 +102,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/console/screenmap b/usr.sbin/bsdconfig/console/screenmap index 643e671..7d72c48 100755 --- a/usr.sbin/bsdconfig/console/screenmap +++ b/usr.sbin/bsdconfig/console/screenmap @@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="$hline_choose_a_screen_map" local prompt="$msg_screenmap_menu_text" @@ -62,12 +62,13 @@ dialog_menu_main() '6 $msg_koi8_u_to_ibm866u' '$msg_koi8_u_to_ibm866u_desc' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get scrnmap )" in [Nn][Oo]|'') defaultitem="1 $msg_none" ;; @@ -86,7 +87,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/console/ttys b/usr.sbin/bsdconfig/console/ttys index 77d5f1b..0fc83fa 100755 --- a/usr.sbin/bsdconfig/console/ttys +++ b/usr.sbin/bsdconfig/console/ttys @@ -72,16 +72,16 @@ TTY_MENU_LIST=" # dialog_menu_main() { - local size local hline="$hline_choose_a_terminal_type" local prompt="$msg_ttys_menu_text" - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $TTY_MENU_LIST ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $TTY_MENU_LIST local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -90,7 +90,8 @@ dialog_menu_main() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $TTY_MENU_LIST \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/mouse/disable b/usr.sbin/bsdconfig/mouse/disable index 89ec176..09142a5 100755 --- a/usr.sbin/bsdconfig/mouse/disable +++ b/usr.sbin/bsdconfig/mouse/disable @@ -86,16 +86,14 @@ f_sysrc_delete moused_flags || f_die f_dialog_title "$msg_message" hline="$hline_press_enter_or_space" prompt="$msg_mouse_daemon_is_disabled" -size=$( f_dialog_buttonbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$prompt" ) -eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$prompt\" $size +f_dialog_buttonbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$prompt" +$DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --msgbox "$prompt" $height $width exit $SUCCESS diff --git a/usr.sbin/bsdconfig/mouse/mouse b/usr.sbin/bsdconfig/mouse/mouse index 7c333c8..6e297cd 100755 --- a/usr.sbin/bsdconfig/mouse/mouse +++ b/usr.sbin/bsdconfig/mouse/mouse @@ -48,7 +48,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size + local menu_list local hline="" local prompt="$msg_menu_text" @@ -61,12 +61,13 @@ dialog_menu_main() '6 $msg_disable' '$msg_disable_the_mouse_daemon' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -76,7 +77,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/mouse/port b/usr.sbin/bsdconfig/mouse/port index c0bc61e..c8d9586 100755 --- a/usr.sbin/bsdconfig/mouse/port +++ b/usr.sbin/bsdconfig/mouse/port @@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="" local prompt="$msg_port_menu_text" @@ -62,12 +62,13 @@ dialog_menu_main() '6 $msg_busmouse' '$msg_busmouse_desc' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get moused_port )" in /dev/psm0) defaultitem="1 $msg_ps2" ;; @@ -86,7 +87,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/mouse/type b/usr.sbin/bsdconfig/mouse/type index 92745c6..0cd3fb7 100755 --- a/usr.sbin/bsdconfig/mouse/type +++ b/usr.sbin/bsdconfig/mouse/type @@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="" local prompt="$msg_protocol_menu_text" @@ -66,12 +66,13 @@ dialog_menu_main() 'A $msg_thinkingmouse' '$msg_thinkingmouse_desc' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get moused_type )" in auto) defaultitem="1 $msg_auto" ;; @@ -94,7 +95,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/networking/networking b/usr.sbin/bsdconfig/networking/networking index 8c9468d..5f69ccb 100755 --- a/usr.sbin/bsdconfig/networking/networking +++ b/usr.sbin/bsdconfig/networking/networking @@ -48,7 +48,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size + local menu_list local hline="$hline_arrows_tab_enter" menu_list=" @@ -59,12 +59,13 @@ dialog_menu_main() '4' '$msg_dns_nameservers' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -74,7 +75,9 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\" $size $menu_list \ + --menu \"\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? diff --git a/usr.sbin/bsdconfig/networking/share/device.subr b/usr.sbin/bsdconfig/networking/share/device.subr index b47bfc9..f248c39 100644 --- a/usr.sbin/bsdconfig/networking/share/device.subr +++ b/usr.sbin/bsdconfig/networking/share/device.subr @@ -142,14 +142,15 @@ f_dialog_menu_netdev() # # Ask user to select an interface # - local prompt size + local prompt prompt="$msg_select_network_interface" - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $interfaces ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $interfaces local dialog_menu dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -158,7 +159,8 @@ f_dialog_menu_netdev() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $interfaces \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -175,7 +177,7 @@ f_dialog_menu_netdev() f_dialog_menu_netdev_edit() { local interface="$1" ipaddr="$2" netmask="$3" options="$4" dhcp="$5" - local prompt menu_list size + local prompt menu_list height width rows # # Create a duplicate set of variables for change-tracking... @@ -216,12 +218,12 @@ f_dialog_menu_netdev_edit() '4 $msg_netmask' '$netmask' '5 $msg_options' '$options' " - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -233,7 +235,8 @@ f_dialog_menu_netdev_edit() --help-label \"\$msg_help\" \ ${USE_XDIALOG:+--help \"\"} \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/networking/share/resolv.subr b/usr.sbin/bsdconfig/networking/share/resolv.subr index c37e719..e439d38 100644 --- a/usr.sbin/bsdconfig/networking/share/resolv.subr +++ b/usr.sbin/bsdconfig/networking/share/resolv.subr @@ -393,10 +393,12 @@ f_dialog_input_nameserver() # f_dialog_menu_nameservers() { + + local height width rows local opt_exit="$msg_return_to_previous_menu" local opt_add="$msg_add_nameserver" local hline="$hline_arrows_tab_enter" - local prompt size defaultitem= + local prompt defaultitem= # # Loop forever until the user has finished configuring nameservers @@ -427,12 +429,12 @@ f_dialog_menu_nameservers() # # Display configuration-edit menu # - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -441,7 +443,8 @@ f_dialog_menu_nameservers() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/password/share/password.subr b/usr.sbin/bsdconfig/password/share/password.subr index ba1f612..2d407c4 100644 --- a/usr.sbin/bsdconfig/password/share/password.subr +++ b/usr.sbin/bsdconfig/password/share/password.subr @@ -46,23 +46,25 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr f_dialog_input_password() { local hline="$hline_alnum_punc_tab_enter" - local msg size rmsg rsize + local msg rmsg msg=$( printf "$msg_enter_new_password" ) - size=$( f_dialog_inputbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "" \ - "$hline" ) + local height1 width1 + f_dialog_inputbox_size height1 width1 \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "" \ + "$hline" rmsg=$( printf "$msg_reenter_password" ) - rsize=$( f_dialog_inputbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$rmsg" \ - "" \ - "$hline" ) + local height2 width2 + f_dialog_inputbox_size height2 width2 \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$rmsg" \ + "" \ + "$hline" # # Loop until the user provides taint-free/valid input @@ -70,14 +72,15 @@ f_dialog_input_password() local retval _password1 _password2 while :; do local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --insecure \ - --passwordbox \"\$msg\" $size \ + dialog_inputbox=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$msg" \ + $height1 $width1 \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -88,14 +91,15 @@ f_dialog_input_password() # Return if user has either pressed ESC or chosen Cancel/No [ $retval -eq $SUCCESS ] || return $retval - dialog_inputbox=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --insecure \ - --passwordbox \"\$rmsg\" $rsize \ + dialog_inputbox=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$rmsg" \ + $height2 $width2 \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/security/kern_securelevel b/usr.sbin/bsdconfig/security/kern_securelevel index ca71a1e..6681da8 100755 --- a/usr.sbin/bsdconfig/security/kern_securelevel +++ b/usr.sbin/bsdconfig/security/kern_securelevel @@ -51,7 +51,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size defaultitem= + local menu_list defaultitem= local hline="$hline_select_securelevel_to_operate_at" local prompt="$msg_securelevels_menu_text" @@ -62,12 +62,13 @@ dialog_menu_main() '$msg_network_secure' '$msg_network_secure_mode' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list case "$( f_sysrc_get kern_securelevel_enable )" in [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) @@ -91,7 +92,8 @@ dialog_menu_main() --help-label \"\$msg_help\" \ ${USE_XDIALOG:+--help \"\"} \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/security/security b/usr.sbin/bsdconfig/security/security index 36a8aae..1000e45 100755 --- a/usr.sbin/bsdconfig/security/security +++ b/usr.sbin/bsdconfig/security/security @@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size mark=" " defaultitem= + local menu_list mark=" " defaultitem= local hline="$hline_arrows_tab_enter" local prompt="$msg_menu_text" @@ -97,12 +97,13 @@ dialog_menu_main() # Update default-item if appropriate [ "$ditem" = 3 ] && defaultitem="3 [$mark] $msg_nfs_port" - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -112,7 +113,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/share/device.subr b/usr.sbin/bsdconfig/share/device.subr index c1a7b16..f973bb8 100644 --- a/usr.sbin/bsdconfig/share/device.subr +++ b/usr.sbin/bsdconfig/share/device.subr @@ -607,13 +607,13 @@ f_device_menu() menu_list="$menu_list '$dev' '$desc'" done - local size mtag - size=$( eval f_dialog_menu_size \ - \"\$title\" \ - \"\$btitle\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local errexit= case $- in *e*) errexit=1; esac @@ -630,7 +630,8 @@ f_device_menu() --help-label \"\$msg_help\" \ ${USE_XDIALOG:+--help \"\"} \ } \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr index 294dbf0..f906487 100644 --- a/usr.sbin/bsdconfig/share/dialog.subr +++ b/usr.sbin/bsdconfig/share/dialog.subr @@ -83,6 +83,28 @@ unset XDIALOG_INFOBOX_TIMEOUT # : ${DEFAULT_TERMINAL_SIZE:=24 80} +# +# Minimum width(s) for various dialog(1) implementations (sensible global +# default(s) for all widgets of a given variant) +# +: ${DIALOG_MIN_WIDTH:=24} +: ${XDIALOG_MIN_WIDTH:=35} + +# +# When manually sizing Xdialog(1) widgets such as calendar and timebox, you'll +# need to know the size of the embedded GUI objects because the height passed +# to Xdialog(1) for these widgets has to be tall enough to accomodate them. +# +# These values are helpful when manually sizing with dialog(1) too, but in a +# different way. dialog(1) does not make you accomodate the custom items in the +# height (but does for width) -- a height of 3 will display three lines and a +# full calendar, for example (whereas Xdialog will truncate the calendar if +# given a height of 3). For dialog(1), use these values for making sure that +# the height does not exceed max_height (obtained by f_dialog_max_size()). +# +DIALOG_CALENDAR_HEIGHT=15 +DIALOG_TIMEBOX_HEIGHT=6 + ############################################################ GENERIC FUNCTIONS # f_dialog_title [$new_title] @@ -174,889 +196,1163 @@ f_dialog_backtitle_restore() ############################################################ SIZE FUNCTIONS -# f_dialog_infobox_size $title $backtitle $prompt [$hline] +# f_dialog_max_size $var_height $var_width # -# Not all versions of dialog(1) perform auto-sizing of the width and height of -# `--infobox' boxes sensibly. +# Get the maximum height and width for a dialog widget and store the values in +# $var_height and $var_width (respectively). # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, and [optionally] hline returning -# the optimal width and height for the box (not exceeding the actual terminal -# width or height). -# -# Newline character sequences (``\n'') in $prompt are expanded as-is done by -# dialog(1). -# -# Output is in the format of "height width". -# -f_dialog_infobox_size() +f_dialog_max_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" n=0 - local min_width max_size - + local __var_height="$1" __var_width="$2" __max_size + [ "$__var_height" -o "$__var_width" ] || return $FAILURE if [ "$USE_XDIALOG" ]; then - min_width=35 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION + __max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION else - min_width=24 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} + __max_size=$( stty size 2> /dev/null ) # usually "24 80" + : ${__max_size:=$DEFAULT_TERMINAL_SIZE} fi + [ "$__var_height" ] && setvar "$__var_height" "${__max_size%%[$IFS]*}" + [ "$__var_width" ] && setvar "$__var_width" "${__max_size##*[$IFS]}" +} - local max_height="${max_size%%[$IFS]*}" - local max_width="${max_size##*[$IFS]}" - local height width=$min_width +# f_dialog_size_constrain $var_height $var_width [$min_height [$min_width]] +# +# Modify $var_height to be no-less-than $min_height (if given; zero otherwise) +# and no-greater-than terminal height (or screen height if $USE_XDIALOG is +# set). +# +# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or +# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal +# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by +# passing $min_width. +# +# Return status is success unless one of the passed arguments is invalid +# or all of the $var_* arguments are either NULL or missing. +# +f_dialog_size_constrain() +{ + local __var_height="$1" __var_width="$2" + local __min_height="$3" __min_width="$4" + local __retval=$SUCCESS + + # Return failure unless at least one var_* argument is passed + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # + # Print debug warnings if any given (non-NULL) argument are invalid + # NOTE: Don't change the name of $__{var,min,}{height,width} + # + local __height __width + local __arg __cp __fname=f_dialog_size_constrain + for __arg in height width; do + debug= f_getvar __var_$__arg __cp + [ "$__cp" ] || continue + if ! f_getvar "$__cp" __$__arg; then + f_dprintf "%s: var_%s variable \`%s' not set" \ + $__fname $__arg "$__cp" + __retval=$FAILURE + elif ! eval f_isinteger \$__$__arg; then + f_dprintf "%s: var_%s variable value not a number" \ + $__fname $__arg + __retval=$FAILURE + fi + done + for __arg in height width; do + debug= f_getvar __min_$__arg __cp + [ "$__cp" ] || continue + f_isinteger "$__cp" && continue + f_dprintf "%s: min_%s value not a number" $__fname $__arg + __retval=$FAILURE + setvar __min_$__arg "" + done - # - # Bump width for long titles (but don't exceed terminal width). - # - n=$(( ${#title} + 4 )) - if [ $n -gt $width -a $n -gt $min_width ]; then - # Add 16.6% width for Xdialog(1) - [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) + # Obtain maximum height and width values + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __max_height_size_constain __max_width_size_constrain + f_dialog_max_size \ + __max_height_size_constrain __max_width_size_constrain + + # Adjust height if desired + if [ "$__var_height" ]; then + if [ $__height -lt ${__min_height:-0} ]; then + setvar "$__var_height" $__min_height + elif [ $__height -gt $__max_height_size_constrain ]; then + setvar "$__var_height" $__max_height_size_constrain + fi + fi - if [ $n -lt $max_width ]; then - width=$n + # Adjust width if desired + if [ "$__var_width" ]; then + if [ "$USE_XDIALOG" ]; then + : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} else - width=$max_width + : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} + fi + if [ $__width -lt $__min_width ]; then + setvar "$__var_width" $__min_width + elif [ $__width -gt $__max_width_size_constrain ]; then + setvar "$__var_width" $__max_width_size_constrain fi fi - # - # For Xdialog(1), bump width for long backtitles (which appear within - # the window; don't exceed maximum width). - # - if [ "$USE_XDIALOG" ]; then - n=$(( ${#btitle} + 4 )) - n=$(( $n + $n / 6 )) - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi + return $__retval # success if no debug warnings were printed +} + +# f_dialog_menu_constrain $var_height $var_width $var_rows "$prompt" \ +# [$min_height [$min_width [$min_rows]]] +# +# Modify $var_height to be no-less-than $min_height (if given; zero otherwise) +# and no-greater-than terminal height (or screen height if $USE_XDIALOG is +# set). +# +# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or +# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal +# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by +# passing $min_width. +# +# Last, modify $var_rows to be no-less-than $min_rows (if specified; zero +# otherwise) and no-greater-than (max_height - 8) where max_height is the +# terminal height (or screen height if $USE_XDIALOG is set). If $prompt is NULL +# or missing, dialog(1) allows $var_rows to be (max_height - 7), maximizing the +# number of visible rows. +# +# Return status is success unless one of the passed arguments is invalid +# or all of the $var_* arguments are either NULL or missing. +# +f_dialog_menu_constrain() +{ + local __var_height="$1" __var_width="$2" __var_rows="$3" __prompt="$4" + local __min_height="$5" __min_width="$6" __min_rows="$7" + + # Return failure unless at least one var_* argument is passed + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # + # Print debug warnings if any given (non-NULL) argument are invalid + # NOTE: Don't change the name of $__{var,min,}{height,width,rows} + # + local __height __width __rows + local __arg __cp __fname=f_dialog_menu_constrain + for __arg in height width rows; do + debug= f_getvar __var_$__arg __cp + [ "$__cp" ] || continue + if ! f_getvar "$__cp" __$__arg; then + f_dprintf "%s: var_%s variable \`%s' not set" \ + $__fname $__arg "$__cp" + __retval=$FAILURE + elif ! eval f_isinteger \$__$__arg; then + f_dprintf "%s: var_%s variable value not a number" \ + $__fname $__arg + __retval=$FAILURE + fi + done + for __arg in height width rows; do + debug= f_getvar __min_$__arg __cp + [ "$__cp" ] || continue + f_isinteger "$__cp" && continue + f_dprintf "%s: min_%s value not a number" $__fname $__arg + __retval=$FAILURE + setvar __min_$__arg "" + done + + # Obtain maximum height and width values + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __max_height_menu_constrain __max_width_menu_constrain + f_dialog_max_size \ + __max_height_menu_constrain __max_width_menu_constrain + + # Adjust height if desired + if [ "$__var_height" ]; then + if [ $__height -lt ${__min_height:-0} ]; then + setvar "$__var_height" $__min_height + elif [ $__height -gt $__max_height_menu_constrain ]; then + setvar "$__var_height" $__max_height_menu_constrain fi fi - # - # Bump width for long prompts (if not already at maximum width). - # - if [ $width -lt $max_width ]; then - n=$( echo "$prompt" | f_longest_line_length ) - n=$(( $n + 4 )) - - # Add 16.6% width for Xdialog(1) - [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) - - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi + # Adjust width if desired + if [ "$__var_width" ]; then + if [ "$USE_XDIALOG" ]; then + : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} + else + : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} + fi + if [ $__width -lt $__min_width ]; then + setvar "$__var_width" $__min_width + elif [ $__width -gt $__max_width_menu_constrain ]; then + setvar "$__var_width" $__max_width_menu_constrain fi fi - # - # Bump width for long hlines (if not already at maximum width). - # NOTE: Though Xdialog(1) supports `--hline', it's not currently used. - # - if [ ! "$USE_XDIALOG" ]; then - if [ $width -lt $max_width ]; then - n=$(( ${#hline} + 10 )) - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi - fi + # Adjust rows if desired + if [ "$__var_rows" ]; then + if [ "$USE_XDIALOG" ]; then + : ${__min_rows:=1} + else + : ${__min_rows:=0} + fi + + local __max_rows=$(( $__max_height_menu_constrain - 8 )) + # If prompt_len is zero (no prompt), bump the max-rows by 1 + # Default assumption is (if no argument) that there's no prompt + [ ${__prompt_len:-0} -gt 0 ] || + __max_rows=$(( $__max_rows + 1 )) + + if [ $__rows -lt $__min_rows ]; then + setvar "$__var_rows" $__min_rows + elif [ $__rows -gt $__max_rows ]; then + setvar "$__var_rows" $__max_rows fi fi - # - # Set height based on number of rows in prompt - # - height=$( echo -n "$prompt" | f_number_of_lines ) - height=$(( $height + 2 )) + return $__retval # success if no debug warnings were printed +} - # - # For Xdialog(1) bump height if backtitle is enabled (displayed in the - # X11 window with a separator line between the backtitle and msg text) - # - if [ "$USE_XDIALOG" -a "$btitle" ]; then - n=$( echo "$btitle" | f_number_of_lines ) - height=$(( $height + $n + 2 )) +# f_dialog_infobox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt [$hline] +# +# Not all versions of dialog(1) perform auto-sizing of the width and height of +# `--infobox' boxes sensibly. +# +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optimal height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. +# +# Newline character sequences (``\n'') in $prompt are expanded as-is done by +# dialog(1). +# +f_dialog_infobox_size() +{ + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Default height/width of zero for auto-sizing + local __height=0 __width=0 __n + + # Adjust height if desired + if [ "$__var_height" ]; then + # + # Set height based on number of rows in prompt + # + __n=$( echo -n "$__prompt" | f_number_of_lines ) + __n=$(( $__n + 2 )) + [ $__n -gt $__height ] && __height=$__n + + # + # For Xdialog(1) bump height if backtitle is enabled (displayed + # in the X11 window with a separator line between the backtitle + # and msg text). + # + if [ "$USE_XDIALOG" -a "$__btitle" ]; then + __n=$( echo "$__btitle" | f_number_of_lines ) + __height=$(( $__height + $__n + 2 )) + fi + + setvar "$__var_height" $__height fi - # Make sure height is less than maximum screen size - [ $height -le $max_height ] || height=$max_height + # Adjust width if desired + if [ "$__var_width" ]; then + # + # Bump width for long titles + # + __n=$(( ${#__title} + 4 )) + [ $__n -gt $__width ] && __width=$__n + + # + # If using Xdialog(1), bump width for long backtitles (which + # appear within the window). + # + if [ "$USE_XDIALOG" ]; then + __n=$(( ${#__btitle} + 4 )) + [ $__n -gt $__width ] && __width=$__n + fi + + # + # Bump width for long prompts + # + __n=$( echo "$__prompt" | f_longest_line_length ) + __n=$(( $__n + 4 )) # add width for border + [ $__n -gt $__width ] && __width=$__n + + # + # Bump width for long hlines. Xdialog(1) supports `--hline' but + # it's currently not used (so don't do anything here if using + # Xdialog(1)). + # + if [ ! "$USE_XDIALOG" ]; then + __n=$(( ${#__hline} + 10 )) + [ $__n -gt $__width ] && __width=$__n + fi - # Return both - echo "$height $width" + # Bump width by 16.6% if using Xdialog(1) + [ "$USE_XDIALOG" ] && __width=$(( $__width + $__width / 6 )) + + setvar "$__var_width" $__width + fi + + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" } -# f_dialog_buttonbox_size $title $backtitle $prompt [$hline] +# f_dialog_buttonbox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--msgbox' and `--yesno' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, and [optionally] hline returning -# the optimal width and height for the box (not exceeding the actual terminal -# width or height). +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optimal height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # -# Output is in the format of "height width". -# f_dialog_buttonbox_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" - local size="$( f_dialog_infobox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local height="${size%%[$IFS]*}" - local width="${size##*[$IFS]}" - - # Add height to accomodate the buttons - height=$(( $height + 2 )) - - # Adjust for clipping with Xdialog(1) on Linux/GTK2 - [ "$USE_XDIALOG" ] && height=$(( $height + 3 )) + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_bbox_size __width_bbox_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_bbox_size}" \ + "${__var_width:+__width_bbox_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add height to accomodate the buttons + __height_bbox_size=$(( $__height_bbox_size + 2 )) + + # Adjust for clipping with Xdialog(1) on Linux/GTK2 + [ "$USE_XDIALOG" ] && + __height_bbox_size=$(( $__height_bbox_size + 3 )) + + setvar "$__var_height" $__height_bbox_size + fi - # - # Enforce maximum height regardless - # - local max_size - if [ "$USE_XDIALOG" ]; then - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} + # No adjustemnts to width, just pass-thru the infobox width + if [ "$__var_width" ]; then + setvar "$__var_width" $__width_bbox_size fi - local max_height="${max_size%%[$IFS]*}" - [ $height -le $max_height ] || height=$max_height - # Return both - echo "$height $width" + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" } -# f_dialog_inputbox_size $title $backtitle $prompt $init [$hline] +# f_dialog_inputbox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt $init [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--inputbox' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, initial text, and [optionally] -# hline returning the optimal width and height for the box (not exceeding the -# actual terminal width and height). +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optimal height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # -# Output is in the format of "height width". -# f_dialog_inputbox_size() { - local title="$1" btitle="$2" prompt="$3" init="$4" hline="$5" n - local size="$( f_dialog_buttonbox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local height="${size%%[$IFS]*}" - local width="${size##*[$IFS]}" - - local min_width max_size - if [ "$USE_XDIALOG" ]; then - min_width=35 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - min_width=24 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __init="$6" __hline="$7" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Calculate height/width of buttonbox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_ibox_size __width_ibox_size + f_dialog_buttonbox_size -n \ + "${__var_height:+__height_ibox_size}" \ + "${__var_width:+__width_ibox_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add height for input box (not needed for Xdialog(1)) + [ ! "$USE_XDIALOG" ] && + __height_ibox_size=$(( $__height_ibox_size + 3 )) + + setvar "$__var_height" $__height_ibox_size fi - local max_height="${max_size%%[$IFS]*}" - local max_width="${max_size##*[$IFS]}" - - # - # Add height to accomodate the input box - # - [ ! "$USE_XDIALOG" ] && height=$(( $height + 3 )) - [ $height -le $max_height ] || height=$max_height - # - # Bump width for initial text (if not already at maximum width). - # NOTE: Something neither dialog(1)/Xdialog(1) do, but worth it! - # - if [ $width -lt $max_width ]; then - n=$(( ${#init} + 7 )) + # Adjust width if desired + if [ "$__var_width" ]; then + # Bump width for initial text (something neither dialog(1) nor + # Xdialog(1) do, but worth it!; add 16.6% if using Xdialog(1)) + local __n=$(( ${#__init} + 7 )) + [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_ibox_size ] && __width_ibox_size=$__n - # Add 16.6% width for Xdialog(1) - [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) - - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi - fi + setvar "$__var_width" $__width_ibox_size fi - # Return both - echo "$height $width" + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" } -# f_xdialog_2inputsbox_size $title $backtitle $prompt \ +# f_xdialog_2inputsbox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt \ # $label1 $init1 $label2 $init2 # # Xdialog(1) does not perform auto-sizing of the width and height of # `--2inputsbox' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, label for the first field, initial -# text for said field, label for the second field, and initial text for said -# field returning the optimal width and height for the box (not exceeding the -# actual terminal width and height). +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, label for the first field, initial text for said +# field, label for the second field, and initial text for said field. The +# optimal height and width for the described widget (not exceeding the actual +# terminal height or width) is stored in $var_height and $var_width +# (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # Xdialog(1). # -# Output is in the format of "height width". -# f_xdialog_2inputsbox_size() { - local title="$1" btitle="$2" prompt="$3" - local label1="$4" init1="$5" label2="$6" init2="$7" n - local size="$( f_dialog_inputbox_size \ - "$title" "$btitle" "$prompt" "$init1" )" - local height="${size%%[$IFS]*}" - local width="${size##*[$IFS]}" - - local min_width=35 - local max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - local max_height="${max_size%%[$IFS]*}" - local max_width="${max_size##*[$IFS]}" - - # Add height for first label - height=$(( $height + 2 )) - - # - # Bump width for first label text (if not already at maximum width). - # - if [ $width -lt $max_width ]; then - n=$(( ${#label1} + 7 )) - - # Add 16.6% width for Xdialog(1) - n=$(( $n + $n / 6 )) - - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi - fi + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" + local __label1="$6" __init1="$7" __label2="$8" __init2="$9" + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE + + # Calculate height/width of inputbox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_2ibox_size __width_2ibox_size + f_dialog_inputbox_size -n \ + "${__var_height:+__height_2ibox_size}" \ + "${__var_width:+__width_2ibox_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" "$__init1" + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add height for 1st label, 2nd label, and 2nd input box + __height_2ibox_size=$(( $__height_2ibox_size + 2 + 2 + 2 )) + setvar "$__var_height" $__height_2ibox_size fi - # Add height for second label - height=$(( $height + 2 )) - - # - # Bump width for second label text (if not already at maximum width). - # - if [ $width -lt $max_width ]; then - n=$(( ${#label2} + 7 )) - - # Add 16.6% width for Xdialog(1) - n=$(( $n + $n / 6 )) + # Adjust width if desired + if [ "$__var_width" ]; then + local __n - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi - fi - fi - - # Add height for a second inputbox - height=$(( $height + 2 )) - [ $height -le $max_height ] || height=$max_height + # Bump width for first label text (+16.6% since Xdialog(1)) + __n=$(( ${#__label1} + 7 )) + __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n - # - # Bump width for second initial text (if not already at maximum width). - # NOTE: Something neither dialog(1)/Xdialog(1) do, but worth it! - # - if [ $width -lt $max_width ]; then - n=$(( ${#init2} + 7 )) + # Bump width for second label text (+16.6% since Xdialog(1)) + __n=$(( ${#__label2} + 7 )) + __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n - # Add 16.6% width for Xdialog(1) - n=$(( $n + $n / 6 )) + # Bump width for 2nd initial text (something neither dialog(1) + # nor Xdialog(1) do, but worth it!; +16.6% since Xdialog(1)) + __n=$(( ${#__init2} + 7 )) + __n=$(( $__n + $__n / 6 )) + [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi - fi + setvar "$__var_width" $__width_2ibox_size fi - # Return both - echo "$height $width" + # Constrain values to sensible minimums/maximums unless `-n' was passed + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || + f_dialog_size_constrain "$__var_height" "$__var_width" } -# f_dialog_menu_size $title $backtitle $prompt $hline \ +# f_dialog_menu_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ # $tag1 $item1 $tag2 $item2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--menu' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, hline and list of tag/item pairs, -# returning the optimal width and height for the menu (not exceeding the actual -# terminal width or height). +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the menu list itself (comprised of tag/item couplets). The +# optimal height, width, and rows for the described widget (not exceeding the +# actual terminal height or width) is stored in $var_height, $var_width, and +# $var_rows (respectively). # -# Output is in the format of "height width rows". +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. # f_dialog_menu_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" n=0 - local min_width min_rows max_size - - if [ "$USE_XDIALOG" ]; then - min_width=35 - min_rows=1 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - min_width=24 - min_rows=0 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} - fi - - local max_width="${max_size##*[$IFS]}" - local max_height="${max_size%%[$IFS]*}" - local box_size="$( f_dialog_infobox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local box_height="${box_size%%[$IFS]*}" - local box_width="${box_size##*[$IFS]}" - local max_rows=$(( $max_height - 8 )) - local height width=$box_width rows=$min_rows - - shift 4 # title/btitle/prompt/hline - - # If there's no prompt, bump the max-rows by 1 - [ "$prompt" ] || max_rows=$(( $max_rows + 1 )) - - # - # The sum total between the longest tag-length and longest item-length - # should be used for the menu width (not to exceed terminal width). - # - # Also, calculate the number of rows (not to exceed terminal height). - # - local longest_tag=0 longest_item=0 + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" __var_rows="$3" + local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" + shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_menu_size __width_menu_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_menu_size}" \ + "${__var_width:+__width_menu_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # + # Always process the menu-item arguments to get the longest tag-length, + # longest item-length (both used to bump the width), and the number of + # rows (used to bump the height). + # + local __longest_tag=0 __longest_item=0 __rows=0 while [ $# -ge 2 ]; do - local tag="$1" item="$2" + local __tag="$1" __item="$2" shift 2 # tag/item - - [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag} - [ ${#item} -gt $longest_item ] && longest_item=${#item} - [ $rows -lt $max_rows ] && rows=$(( $rows + 1 )) + [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} + [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} + __rows=$(( $__rows + 1 )) done - # Update width - n=$(( $longest_tag + $longest_item + 10 )) - [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1) - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n + # Adjust rows early (for up-comning height calculation) + if [ "$__var_height" -o "$__var_rows" ]; then + # Add a row for visual aid if using Xdialog(1) + [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) + fi + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add rows to height + if [ "$USE_XDIALOG" ]; then + __height_menu_size=$(( + $__height_menu_size + $__rows + 7 )) else - width=$max_width + __height_menu_size=$(( + $__height_menu_size + $__rows + 4 )) fi + setvar "$__var_height" $__height_menu_size fi - # Fix rows and set height - [ $rows -gt 0 ] || rows=1 - if [ "$USE_XDIALOG" ]; then - height=$(( $rows + $box_height + 7 )) - else - height=$(( $rows + $box_height + 4 )) + # Adjust width if desired + if [ "$__var_width" ]; then + # The sum total between the longest tag-length and the + # longest item-length should be used to bump menu width + local __n=$(( $__longest_tag + $__longest_item + 10 )) + [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% + [ $__n -gt $__width_menu_size ] && __width_menu_size=$__n + + setvar "$__var_width" $__width_menu_size fi - [ $height -le $max_height ] || height=$max_height - # Return all three - echo "$height $width $rows" + # Store adjusted rows if desired + [ "$__var_rows" ] && setvar "$__var_rows" $__rows + + # Constrain height, width, and rows to sensible minimum/maximum values + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || f_dialog_menu_constrain \ + "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } -# f_dialog_menu_with_help_size $title $backtitle $prompt $hline \ +# f_dialog_menu_with_help_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ # $tag1 $item1 $help1 $tag2 $item2 $help2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--menu' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, hline and list of tag/item/help -# triplets, returning the optimal width and height for the menu (not exceeding -# the actual terminal width or height). +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the menu list itself (comprised of tag/item/help triplets). The +# optimal height, width, and rows for the described widget (not exceeding the +# actual terminal height or width) is stored in $var_height, $var_width, and +# $var_rows (respectively). # -# Output is in the format of "height width rows". +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. # f_dialog_menu_with_help_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" n=0 - local min_width min_rows max_size - - if [ "$USE_XDIALOG" ]; then - min_width=35 - min_rows=1 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - min_width=24 - min_rows=0 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} - fi - - local max_width="${max_size##*[$IFS]}" - local max_height="${max_size%%[$IFS]*}" - local box_size="$( f_dialog_infobox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local box_height="${box_size%%[$IFS]*}" - local box_width="${box_size##*[$IFS]}" - local max_rows=$(( $max_height - 8 )) - local height width=$box_width rows=$min_rows - - shift 4 # title/btitle/prompt/hline - - # If there's no prompt, bump the max-rows by 1 - [ "$prompt" ] || max_rows=$(( $max_rows + 1 )) - - # - # The sum total between the longest tag-length and longest item-length - # should be used for the menu width (not to exceed terminal width). - # - # Also, calculate the number of rows (not to exceed terminal height). - # - # Also, calculate the longest help while we're here. This will be used - # to influence the width of the menu if (and only-if) using Xdialog(1). - # - local longest_tag=0 longest_item=0 longest_help=0 + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" __var_rows="$3" + local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" + shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_menu_with_help_size __width_menu_with_help_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_menu_with_help_size}" \ + "${__var_width:+__width_menu_with_help_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # + # Always process the menu-item arguments to get the longest tag-length, + # longest item-length, longest help-length (help-length only considered + # if using Xdialog(1), as it places the help string in the widget) -- + # all used to bump the width -- and the number of rows (used to bump + # the height). + # + local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0 while [ $# -ge 3 ]; do - local tag="$1" item="$2" help="$3" + local __tag="$1" __item="$2" __help="$3" shift 3 # tag/item/help - - [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag} - [ ${#item} -gt $longest_item ] && longest_item=${#item} - [ ${#help} -gt $longest_help ] && longest_help=${#help} - [ $rows -lt $max_rows ] && rows=$(( $rows + 1 )) + [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} + [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} + [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help} + __rows=$(( $__rows + 1 )) done - # Update width - n=$(( $longest_tag + $longest_item + 10 )) - [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1) - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n + # Adjust rows early (for up-coming height calculation) + if [ "$__var_height" -o "$__var_rows" ]; then + # Add a row for visual aid if using Xdialog(1) + [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) + fi + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add rows to height + if [ "$USE_XDIALOG" ]; then + __height_menu_with_help_size=$(( + $__height_menu_with_help_size + $__rows + 8 )) else - width=$max_width + __height_menu_with_help_size=$(( + $__height_menu_with_help_size + $__rows + 4 )) fi + setvar "$__var_height" $__height_menu_with_help_size fi - # Update width for help text if using Xdialog(1) - if [ "$USE_XDIALOG" ]; then - n=$(( $longest_help + 10 )) - n=$(( $n + $n / 6 )) # +16.6% - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi + # Adjust width if desired + if [ "$__var_width" ]; then + # The sum total between the longest tag-length and the + # longest item-length should be used to bump menu width + local __n=$(( $__longest_tag + $__longest_item + 10 )) + [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% + [ $__n -gt $__width_menu_with_help_size ] && + __width_menu_with_help_size=$__n + + # Update width for help text if using Xdialog(1) + if [ "$USE_XDIALOG" ]; then + __n=$(( $__longest_help + 10 )) + __n=$(( $__n + $__n / 6 )) # plus 16.6% + [ $__n -gt $__width_menu_with_help_size ] && + __width_menu_with_help_size=$__n fi - fi - # Fix rows and set height - [ $rows -gt 0 ] || rows=1 - if [ "$USE_XDIALOG" ]; then - height=$(( $rows + $box_height + 8 )) - else - height=$(( $rows + $box_height + 4 )) + setvar "$__var_width" $__width_menu_with_help_size fi - [ $height -le $max_height ] || height=$max_height - # Return all three - echo "$height $width $rows" + # Store adjusted rows if desired + [ "$__var_rows" ] && setvar "$__var_rows" $__rows + + # Constrain height, width, and rows to sensible minimum/maximum values + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || f_dialog_menu_constrain \ + "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } -# f_dialog_radiolist_size $title $backtitle $prompt $hline \ +# f_dialog_radiolist_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $tag2 $item2 $status2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--radiolist' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, hline and list of tag/item/status -# triplets, returning the optimal width and height for the radiolist (not -# exceeding the actual terminal width or height). +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the radio list itself (comprised of tag/item/status triplets). +# The optimal height, width, and rows for the described widget (not exceeding +# the actual terminal height or width) is stored in $var_height, $var_width, +# and $var_rows (respectively). # -# Output is in the format of "height width rows". +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. # f_dialog_radiolist_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" n=0 - local min_width min_rows max_size - - if [ "$USE_XDIALOG" ]; then - min_width=35 - min_rows=1 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - min_width=24 - min_rows=0 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} - fi - - local max_width="${max_size##*[$IFS]}" - local max_height="${max_size%%[$IFS]*}" - local box_size="$( f_dialog_infobox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local box_height="${box_size%%[$IFS]*}" - local box_width="${box_size##*[$IFS]}" - local max_rows=$(( $max_height - 8 )) - local height width=$box_width rows=$min_rows - - shift 4 # title/btitle/prompt/hline - - # - # The sum total between the longest tag-length, longest item-length, - # and radio-button width should be used for the menu width (not to - # exceed terminal width). - # - # Also, calculate the number of rows (not to exceed terminal height). - # - local longest_tag=0 longest_item=0 + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" __var_rows="$3" + local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" + shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_rlist_size __width_rlist_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_rlist_size}" \ + "${__var_width:+__width_rlist_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # + # Always process the menu-item arguments to get the longest tag-length, + # longest item-length (both used to bump the width), and the number of + # rows (used to bump the height). + # + local __longest_tag=0 __longest_item=0 __rows=0 while [ $# -ge 3 ]; do - local tag="$1" item="$2" + local __tag="$1" __item="$2" shift 3 # tag/item/status - - [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag} - [ ${#item} -gt $longest_item ] && longest_item=${#item} - [ $rows -lt $max_rows ] && rows=$(( $rows + 1 )) + [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} + [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} + __rows=$(( $__rows + 1 )) done - # Update width - n=$(( $longest_tag + $longest_item + 13 )) - [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1) - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n + # Adjust rows early (for up-coming height calculation) + if [ "$__var_height" -o "$__var_rows" ]; then + # Add a row for visual aid if using Xdialog(1) + [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) + fi + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add rows to height + if [ "$USE_XDIALOG" ]; then + __height_rlist_size=$(( + $__height_rlist_size + $__rows + 7 )) else - width=$max_width + __height_rlist_size=$(( + $__height_rlist_size + $__rows + 4 )) fi + setvar "$__var_height" $__height_rlist_size fi - # Fix rows and set height - [ $rows -gt 0 ] || rows=1 - if [ "$USE_XDIALOG" ]; then - height=$(( $rows + $box_height + 7 )) - else - height=$(( $rows + $box_height + 4 )) + # Adjust width if desired + if [ "$__var_width" ]; then + # Sum total between longest tag-length, longest item-length, + # and radio-button width should be used to bump menu width + local __n=$(( $__longest_tag + $__longest_item + 13 )) + [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% + [ $__n -gt $__width_rlist_size ] && __width_rlist_size=$__n + + setvar "$__var_width" $__width_rlist_size fi - [ $height -le $max_height ] || height=$max_height - # Return all three - echo "$height $width $rows" + # Store adjusted rows if desired + [ "$__var_rows" ] && setvar "$__var_rows" $__rows + + # Constrain height, width, and rows to sensible minimum/maximum values + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || f_dialog_menu_constrain \ + "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } -# f_dialog_checklist_size $title $backtitle $prompt $hline \ +# f_dialog_checklist_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $tag2 $item2 $status2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--checklist' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, hline and list of tag/item/status -# triplets, returning the optimal width and height for the checklist (not -# exceeding the actual terminal width or height). +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the check list itself (comprised of tag/item/status triplets). +# The optimal height, width, and rows for the described widget (not exceeding +# the actual terminal height or width) is stored in $var_height, $var_width, +# and $var_rows (respectively). # -# Output is in the format of "height width rows". +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. # f_dialog_checklist_size() { f_dialog_radiolist_size "$@" } -# f_dialog_radiolist_with_help_size $title $backtitle $prompt $hline \ +# f_dialog_radiolist_with_help_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $help1 \ # $tag2 $item2 $status2 $help2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--radiolist' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, hline and list of -# tag/item/status/help quads, returning the optimal width and height for the -# radiolist (not exceeding the actual terminal width or height). +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the radio list itself (comprised of tag/item/status/help +# quadruplets). The optimal height, width, and rows for the described widget +# (not exceeding the actual terminal height or width) is stored in $var_height, +# $var_width, and $var_rows (respectively). # -# Output is in the format of "height width rows". +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. # f_dialog_radiolist_with_help_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" n=0 - local min_width min_rows max_size - - if [ "$USE_XDIALOG" ]; then - min_width=35 - min_rows=1 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - min_width=24 - min_rows=0 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} - fi - - local max_width="${max_size##*[$IFS]}" - local max_height="${max_size%%[$IFS]*}" - local box_size="$( f_dialog_infobox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local box_height="${box_size%%[$IFS]*}" - local box_width="${box_size##*[$IFS]}" - local max_rows=$(( $max_height - 8 )) - local height width=$box_width rows=$min_rows - - shift 4 # title/btitle/prompt/hline - - # - # The sum total between the longest tag-length, longest item-length, - # and radio-button width should be used for the menu width (not to - # exceed terminal width). - # - # Also, calculate the number of rows (not to exceed terminal height). - # - # Also, calculate the longest help while we're here. This will be used - # to influence the width of the menu if (and only-if) using Xdialog(1). - # - local longest_tag=0 longest_item=0 longest_help=0 + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" __var_rows="$3" + local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" + shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline + + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || + return $FAILURE + + # Calculate height/width of infobox (adjusted/constrained below) + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). + local __height_rlist_with_help_size __width_rlist_with_help_size + f_dialog_infobox_size -n \ + "${__var_height:+__height_rlist_with_help_size}" \ + "${__var_width:+__width_rlist_with_help_size}" \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # + # Always process the menu-item arguments to get the longest tag-length, + # longest item-length, longest help-length (help-length only considered + # if using Xdialog(1), as it places the help string in the widget) -- + # all used to bump the width -- and the number of rows (used to bump + # the height). + # + local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0 while [ $# -ge 4 ]; do - local tag="$1" item="$2" status="$3" help="$4" + local __tag="$1" __item="$2" __status="$3" __help="$4" shift 4 # tag/item/status/help - - [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag} - [ ${#item} -gt $longest_item ] && longest_item=${#item} - [ ${#help} -gt $longest_help ] && longest_help=${#help} - [ $rows -lt $max_rows ] && rows=$(( $rows + 1 )) + [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} + [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} + [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help} + __rows=$(( $__rows + 1 )) done - # Update width - n=$(( $longest_tag + $longest_item + 13 )) - [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1) - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n + # Adjust rows early (for up-coming height calculation) + if [ "$__var_height" -o "$__var_rows" ]; then + # Add a row for visual aid if using Xdialog(1) + [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) + fi + + # Adjust height if desired + if [ "$__var_height" ]; then + # Add rows to height + if [ "$USE_XDIALOG" ]; then + __height_rlist_with_help_size=$(( + $__height_rlist_with_help_size + $__rows + 7 )) else - width=$max_width + __height_rlist_with_help_size=$(( + $__height_rlist_with_help_size + $__rows + 4 )) fi + setvar "$__var_height" $__height fi - # Update width for help text if using Xdialog(1) - if [ "$USE_XDIALOG" ]; then - n=$(( $longest_help + 10 )) - n=$(( $n + $n / 6 )) # +16.6% - if [ $n -gt $width -a $n -gt $min_width ]; then - if [ $n -lt $max_width ]; then - width=$n - else - width=$max_width - fi + # Adjust width if desired + if [ "$__var_width" ]; then + # Sum total between longest tag-length, longest item-length, + # and radio-button width should be used to bump menu width + local __n=$(( $__longest_tag + $__longest_item + 13 )) + [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% + [ $__n -gt $__width_rlist_with_help_size ] && + __width_rlist_with_help_size=$__n + + # Update width for help text if using Xdialog(1) + if [ "$USE_XDIALOG" ]; then + __n=$(( $__longest_help + 10 )) + __n=$(( $__n + $__n / 6 )) # plus 16.6% + [ $__n -gt $__width_rlist_with_help_size ] && + __width_rlist_with_help_size=$__n fi - fi - # Fix rows and set height - [ $rows -gt 0 ] || rows=1 - if [ "$USE_XDIALOG" ]; then - height=$(( $rows + $box_height + 7 )) - else - height=$(( $rows + $box_height + 4 )) + setvar "$__var_width" $__width_rlist_with_help_size fi - [ $height -le $max_height ] || height=$max_height - # Return all three - echo "$height $width $rows" + # Store adjusted rows if desired + [ "$__var_rows" ] && setvar "$__var_rows" $__rows + + # Constrain height, width, and rows to sensible minimum/maximum values + # Return success if no-constrain, else return status from constrain + [ ! "$__constrain" ] || f_dialog_menu_constrain \ + "$__var_height" "$__var_width" "$__var_rows" "$__prompt" } -# f_dialog_checklist_with_help_size $title $backtitle $prompt $hline \ +# f_dialog_checklist_with_help_size [-n] $var_height $var_width $var_rows \ +# $title $backtitle $prompt $hline \ # $tag1 $item1 $status1 $help1 \ # $tag2 $item2 $status2 $help2 ... # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--checklist' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, hline and list of -# tag/item/status/help quads, returning the optimal width and height for the -# checklist (not exceeding the actual terminal width or height). +# This function helps solve this issue by taking three sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height, width, and rows. The second set of arguments +# are the title, backtitle, prompt, and hline. The [optional] third set of +# arguments are the check list itself (comprised of tag/item/status/help +# quadruplets). The optimal height, width, and rows for the described widget +# (not exceeding the actual terminal height or width) is stored in $var_height, +# $var_width, and $var_rows (respectively). # -# Output is in the format of "height width rows". +# If the first argument is `-n', the calculated sizes ($var_height, $var_width, +# and $var_rows) are not constrained to minimum/maximum values. # f_dialog_checklist_with_help_size() { f_dialog_radiolist_with_help_size "$@" } -# f_dialog_calendar_size $title $backtitle $prompt [$hline] +# f_dialog_calendar_size [-n] $var_height $var_width \ +# $title $backtitle $prompt [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--calendar' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, and [optionally] hline returning -# the optimal width and height for the box (not exceeding the actual terminal -# width and height). +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optimal height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # -# Output is in the format of "height width". -# f_dialog_calendar_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" n - local size="$( f_dialog_infobox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local height="${size%%[$IFS]*}" - local width="${size##*[$IFS]}" - - local min_width min_height max_size - if [ "$USE_XDIALOG" ]; then - min_height=15 - min_width=55 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - min_height=0 - min_width=40 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} - fi - local max_height="${max_size%%[$IFS]*}" - local max_width="${max_size##*[$IFS]}" + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" - # - # Enforce the minimum width for displaying the calendar - # - [ $width -ge $min_width ] || width=$min_width + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE # - # When using dialog(1), the calendar box is unique from other dialog(1) - # boxes in-that the height passed should not accomodate the 15-lines - # required to display the calendar. This does not apply to Xdialog(1). - # - # When using Xdialog(1), the height must accomodate the 15-lines - # required to display the calendar. - # - # NOTE: Also under dialog(1), because we can't predict whether the user - # has disabled shadow's in their `$HOME/.dialogrc' file, we'll subtract - # 16 rather than 15. This does not apply to Xdialog(1). + # Obtain/Adjust minimum and maximum thresholds + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). # - max_height=$(( $max_height - 16 )) - height=$( echo "$prompt" | f_number_of_lines ) + local __max_height_cal_size __max_width_cal_size + f_dialog_max_size __max_height_cal_size __max_width_cal_size + __max_width_cal_size=$(( $__max_width_cal_size - 2 )) + # the calendar box will refuse to display if too wide + local __min_width if [ "$USE_XDIALOG" ]; then - # Add height to accomodate for the embedded calendar widget - height=$(( $height + $min_height - 1 )) + __min_width=55 + else + __min_width=40 + __max_height_cal_size=$(( + $__max_height_cal_size - $DIALOG_CALENDAR_HEIGHT )) + # When using dialog(1), we can't predict whether the user has + # disabled shadow's in their `$HOME/.dialogrc' file, so we'll + # subtract one for the potential shadow around the widget + __max_height_cal_size=$(( $__max_height_cal_size - 1 )) + fi - # Also, bump height if backtitle is enabled - if [ "$btitle" ]; then - local n="$( echo "$btitle" | f_number_of_lines )" - height=$(( $height + $n + 2 )) + # Calculate height if desired + if [ "$__var_height" ]; then + local __height + __height=$( echo "$__prompt" | f_number_of_lines ) + + if [ "$USE_XDIALOG" ]; then + # Add height to accomodate for embedded calendar widget + __height=$(( $__height + $DIALOG_CALENDAR_HEIGHT - 1 )) + + # Also, bump height if backtitle is enabled + if [ "$__btitle" ]; then + local __n + __n=$( echo "$__btitle" | f_number_of_lines ) + __height=$(( $__height + $__n + 2 )) + fi + else + [ "$__prompt" ] && __height=$(( $__height + 1 )) fi - else - [ "$prompt" ] && height=$(( $height + 1 )) + + # Enforce maximum height, unless `-n' was passed + [ "$__constrain" -a $__height -gt $__max_height_cal_size ] && + __height=$__max_height_cal_size + + setvar "$__var_height" $__height fi - [ $height -le $max_height ] || height=$max_height - # - # The calendar box refuses to display if too large. - # - max_width=$(( $max_width - 2 )) - [ $width -le $max_width ] || width=$max_width + # Calculate width if desired + if [ "$__var_width" ]; then + # NOTE: Function name appended to prevent __var_{height,width} + # values from becoming local (and thus preventing setvar + # from working). + local __width_cal_size + f_dialog_infobox_size -n "" __width_cal_size \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # Enforce minimum/maximum width, unless `-n' was passed + if [ "$__constrain" ]; then + if [ $__width_cal_size -lt $__min_width ]; then + __width_cal_size=$__min_width + elif [ $__width_cal_size -gt $__max_width_cal_size ] + then + __width_cal_size=$__max_width_size + fi + fi + + setvar "$__var_width" $__width_cal_size + fi - # Return both - echo "$height $width" + return $SUCCESS } -# f_dialog_timebox_size $title $backtitle $prompt [$hline] +# f_dialog_timebox_size [-n] $var_height $var_width \ +# $title $backtitle $prompt [$hline] # # Not all versions of dialog(1) perform auto-sizing of the width and height of # `--timebox' boxes sensibly. # -# This function helps solve this issue by taking as arguments (in order of -# appearance) the title, backtitle, prompt, and [optionally] hline returning -# the optimal width and height for the box (not exceeding the actual terminal -# width and height). +# This function helps solve this issue by taking two sets of sequential +# arguments. The first set of arguments are the variable names to use when +# storing the calculated height and width. The second set of arguments are the +# title, backtitle, prompt, and [optionally] hline. The optional height and +# width for the described widget (not exceeding the actual terminal height or +# width) is stored in $var_height and $var_width (respectively). +# +# If the first argument is `-n', the calculated sizes ($var_height and +# $var_width) are not constrained to minimum/maximum values. # # Newline character sequences (``\n'') in $prompt are expanded as-is done by # dialog(1). # -# Output is in the format of "height width". -# f_dialog_timebox_size() { - local title="$1" btitle="$2" prompt="$3" hline="$4" n - local size="$( f_dialog_infobox_size \ - "$title" "$btitle" "$prompt" "$hline" )" - local height="${size%%[$IFS]*}" - local width="${size##*[$IFS]}" - - local min_width min_height max_size - if [ "$USE_XDIALOG" ]; then - min_width=40 - max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION - else - min_height=0 - min_width=20 - max_size=$( stty size 2> /dev/null ) # usually "24 80" - : ${max_size:=$DEFAULT_TERMINAL_SIZE} - fi - local max_height="${max_size%%[$IFS]*}" - local max_width="${max_size##*[$IFS]}" + local __constrain=1 + [ "$1" = "-n" ] && __constrain= && shift 1 # -n + local __var_height="$1" __var_width="$2" + local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" - # - # Enforce the minimum width for displaying the timebox - # - [ $width -ge $min_width ] || width=$min_width + # Return unless at least one size aspect has been requested + [ "$__var_height" -o "$__var_width" ] || return $FAILURE # - # When using dialog(1), the timebox box is unique from other dialog(1) - # boxes in-that the height passed should not accomodate the 6-lines - # required to display the timebox. This does not apply to Xdialog(1). - # - # When using Xdialog(1), the height seems to have no effect. All values - # provide the same results. - # - # NOTE: Also under dialog(1), because we can't predict whether the user - # has disabled shadow's in their `$HOME/.dialogrc' file, we'll subtract - # 7 rather than 6. This does not apply to Xdialog(1). + # Obtain/Adjust minimum and maximum thresholds + # NOTE: Function name appended to prevent __var_{height,width} values + # from becoming local (and thus preventing setvar from working). # + local __max_height_tbox_size __max_width_tbox_size + f_dialog_max_size __max_height_tbox_size __max_width_tbox_size + __max_width_tbox_size=$(( $__max_width_tbox_size - 2 )) + # the timebox widget refuses to display if too wide + local __min_width if [ "$USE_XDIALOG" ]; then - height=0 # Autosize; all values produce same results + __min_width=40 else - max_height=$(( $max_height - 7 )) - height=$( echo "$prompt" | f_number_of_lines ) - height=$(( $height + 1 )) - [ $height -le $max_height ] || height=$max_height - [ "$prompt" ] && height=$(( $height + 1 )) + __min_width=20 + __max_height_tbox_size=$(( \ + $__max_height_tbox_size - $DIALOG_TIMEBOX_HEIGHT )) + # When using dialog(1), we can't predict whether the user has + # disabled shadow's in their `$HOME/.dialogrc' file, so we'll + # subtract one for the potential shadow around the widget + __max_height_tbox_size=$(( $__max_height_tbox_size - 1 )) fi - # - # The timebox box refuses to display if too large. - # - max_width=$(( $max_width - 2 )) - [ $width -le $max_width ] || width=$max_width + # Calculate height if desired + if [ "$__var_height" -a "$USE_XDIALOG" ]; then + # When using Xdialog(1), the height seems to have + # no effect. All values provide the same results. + setvar "$__var_height" 0 # autosize + elif [ "$__var_height" ]; then + local __height + __height=$( echo "$__prompt" | f_number_of_lines ) + __height=$(( $__height ${__prompt:++1} + 1 )) + + # Enforce maximum height, unless `-n' was passed + [ "$__constrain" -a $__height -gt $__max_height_tbox_size ] && + __height=$__max_height_tbox_size + + setvar "$__var_height" $__height + fi + + # Calculate width if desired + if [ "$__var_width" ]; then + # NOTE: Function name appended to prevent __var_{height,width} + # values from becoming local (and thus preventing setvar + # from working). + local __width_tbox_size + f_dialog_infobox_size -n "" __width_tbox_size \ + "$__title" "$__btitle" "$__prompt" "$__hline" + + # Enforce the minimum width for displaying the timebox + if [ "$__constrain" ]; then + if [ $__width_tbox_size -lt $__min_width ]; then + __width_tbox_size=$__min_width + elif [ $__width_tbox_size -ge $__max_width_tbox_size ] + then + __width_tbox_size=$__max_width_tbox_size + fi + fi - # Return both - echo "$height $width" + setvar "$__var_width" $__width_tbox_size + fi + + return $SUCCESS } ############################################################ CLEAR FUNCTIONS @@ -1079,18 +1375,15 @@ f_dialog_clear() # f_dialog_info() { - local info_text="$*" - local size="$( f_dialog_infobox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$info_text" )" - - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - ${USE_XDIALOG:+--ignore-eof} \ - ${USE_XDIALOG:+--no-buttons} \ - --infobox \"\$info_text\" $size + local info_text="$*" height width + f_dialog_infobox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text" + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + ${USE_XDIALOG:+--ignore-eof} \ + ${USE_XDIALOG:+--no-buttons} \ + --infobox "$info_text" $height $width } # f_xdialog_info $info_text ... @@ -1101,17 +1394,14 @@ f_dialog_info() # f_xdialog_info() { - local info_text="$*" - local size="$( f_dialog_infobox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$info_text" )" - - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --no-close --no-buttons \ - --infobox \"\$info_text\" $size \ + local info_text="$*" height width + f_dialog_infobox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text" + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --no-close --no-buttons \ + --infobox "$info_text" $height $width \ -1 # timeout of -1 means abort when EOF on stdin } @@ -1127,17 +1417,14 @@ f_xdialog_info() # f_dialog_msgbox() { - local msg_text="$*" - local size="$( f_dialog_buttonbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg_text" )" - - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$msg_text\" $size + local msg_text="$*" height width + f_dialog_buttonbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --ok-label "$msg_ok" \ + --msgbox "$msg_text" $height $width } ############################################################ TEXTBOX FUNCTIONS @@ -1154,29 +1441,27 @@ f_dialog_msgbox() f_dialog_textbox() { local file="$1" - local contents retval size + local contents height width retval contents=$( cat "$file" 2>&1 ) retval=$? - size=$( f_dialog_buttonbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$contents" ) + f_dialog_buttonbox_size height width \ + "$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 + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --exit-label "$msg_ok" \ + --no-cancel \ + --textbox "$file" $height $width else - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$contents\" $size + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --ok-label "$msg_ok" \ + --msgbox "$contents" $height $width fi } @@ -1193,33 +1478,30 @@ f_dialog_textbox() # f_dialog_yesno() { - local msg_text="$*" + local msg_text="$*" height width local hline="$hline_arrows_tab_enter" f_interactive || return 0 # If non-interactive, return YES all the time - local size="$( f_dialog_buttonbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg_text" \ - "$hline" )" + f_dialog_buttonbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline" if [ "$USE_XDIALOG" ]; then - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_yes\" \ - --cancel-label \"\$msg_no\" \ - --yesno \"\$msg_text\" $size + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_yes" \ + --cancel-label "$msg_no" \ + --yesno "$msg_text" $height $width else - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --yes-label \"\$msg_yes\" \ - --no-label \"\$msg_no\" \ - --yesno \"\$msg_text\" $size + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --yes-label "$msg_yes" \ + --no-label "$msg_no" \ + --yesno "$msg_text" $height $width fi } @@ -1236,35 +1518,32 @@ f_dialog_yesno() # f_dialog_noyes() { - local msg_text="$*" + local msg_text="$*" height width local hline="$hline_arrows_tab_enter" f_interactive || return 1 # If non-interactive, return NO all the time - local size="$( f_dialog_buttonbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg_text" \ - "$hline" )" + f_dialog_buttonbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline" if [ "$USE_XDIALOG" ]; then - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --default-no \ - --ok-label \"\$msg_yes\" \ - --cancel-label \"\$msg_no\" \ - --yesno \"\$msg_text\" $size + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --default-no \ + --ok-label "$msg_yes" \ + --cancel-label "$msg_no" \ + --yesno "$msg_text" $height $width else - eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --defaultno \ - --yes-label \"\$msg_yes\" \ - --no-label \"\$msg_no\" \ - --yesno \"\$msg_text\" $size + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --defaultno \ + --yes-label "$msg_yes" \ + --no-label "$msg_no" \ + --yesno "$msg_text" $height $width fi } @@ -1312,26 +1591,25 @@ f_dialog_inputstr() f_dialog_input() { local prompt="$1" init="$2" hline="$3" - local size="$( f_dialog_inputbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$prompt" \ - "$init" \ - "$hline" )" + local height width + f_dialog_inputbox_size height width \ + "$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\" \ + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --inputbox "$prompt" \ + $height $width \ + $opterm "$init" \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? @@ -1609,14 +1887,16 @@ f_dialog_init() then # Xdialog(1) failed, fall back to dialog(1) unset USE_XDIALOG - size=$( f_dialog_buttonbox_size "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$maxsize" "" ) - eval dialog \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$maxsize\" $size + + # Display the error message produced by Xdialog(1) + local height width + f_dialog_buttonbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$maxsize" + dialog \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --ok-label "$msg_ok" \ + --msgbox "$maxsize" $height $width exit $FAILURE fi diff --git a/usr.sbin/bsdconfig/share/media/any.subr b/usr.sbin/bsdconfig/share/media/any.subr index 1193282..11fe429 100644 --- a/usr.sbin/bsdconfig/share/media/any.subr +++ b/usr.sbin/bsdconfig/share/media/any.subr @@ -69,7 +69,7 @@ f_media_get_type() f_dialog_title_restore local prompt="$msg_choose_installation_media_description" local hline="$hline_choose_help_for_more_information_on_media_types" - local menu_list size + local menu_list menu_list=" '1 $msg_cd_dvd' '$msg_install_from_a_freebsd_cd_dvd' @@ -86,26 +86,29 @@ f_media_get_type() 'X $msg_options' '$msg_view_set_various_media_options' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$title\" \ - \"\$btitle\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu while :; do dialog_menu=$( eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --help-button \ - --help-label \"\$msg_help\" \ - ${USE_XDIALOG:+--help \"\"} \ - --menu \"\$prompt\" $size $menu_list \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --help-button \ + --help-label \"\$msg_help\" \ + ${USE_XDIALOG:+--help \"\"} \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? diff --git a/usr.sbin/bsdconfig/share/media/ftp.subr b/usr.sbin/bsdconfig/share/media/ftp.subr index 4f6add0..639f7c3 100644 --- a/usr.sbin/bsdconfig/share/media/ftp.subr +++ b/usr.sbin/bsdconfig/share/media/ftp.subr @@ -229,13 +229,13 @@ f_dialog_menu_media_ftp() ' $msg_usa #15' 'ftp15.us.freebsd.org' " # END-QUOTE - local size - size=$( eval f_dialog_menu_size \ - \"\$title\" \ - \"\$btitle\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu retval mtag value dialog_menu=$( eval $DIALOG \ @@ -244,7 +244,8 @@ f_dialog_menu_media_ftp() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/share/media/options.subr b/usr.sbin/bsdconfig/share/media/options.subr index 5147056..b891956 100644 --- a/usr.sbin/bsdconfig/share/media/options.subr +++ b/usr.sbin/bsdconfig/share/media/options.subr @@ -55,7 +55,7 @@ f_media_options_menu() f_dialog_title_restore local prompt="" local hline="$hline_arrows_tab_enter" - local menu_list size cp + local menu_list cp # # A hack so that the dialogs below are always interactive in a script @@ -200,27 +200,30 @@ f_media_options_menu() '$msg_reset_all_values_to_startup_defaults' " # END-QUOTE - size=$( eval f_dialog_menu_with_help_size \ - \"\$title\" \ - \"\$btitle\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_with_help_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --hline \"\$hline\" \ - --item-help \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_done\" \ - --help-button \ - --help-label \"\$msg_help\" \ - --default-item \"\$defaultitem\" \ - ${USE_XDIALOG:+--help \"\"} \ - --menu \"\$prompt\" $size $menu_list \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --hline \"\$hline\" \ + --item-help \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_done\" \ + --help-button \ + --help-label \"\$msg_help\" \ + --default-item \"\$defaultitem\" \ + ${USE_XDIALOG:+--help \"\"} \ + --menu \"\$prompt\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? diff --git a/usr.sbin/bsdconfig/share/mustberoot.subr b/usr.sbin/bsdconfig/share/mustberoot.subr index ebfe812..14e846f 100644 --- a/usr.sbin/bsdconfig/share/mustberoot.subr +++ b/usr.sbin/bsdconfig/share/mustberoot.subr @@ -77,7 +77,7 @@ SECURE_DIVULGE_UNKNOWN_USER= # f_become_root_via_sudo() { - local msg hline size + local msg hline height width rows [ "$( id -u )" = "0" ] && return $SUCCESS @@ -98,12 +98,12 @@ f_become_root_via_sudo() " # END-QUOTE msg=$( printf "$msg_you_are_not_root_but" bsdconfig ) hline="$hline_arrows_tab_enter" - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$msg\" \ - \"\$hline\" \ - $menu_list ) + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$msg\" \ + \"\$hline\" \ + $menu_list local dialog_menu mtag retval dialog_menu=$( eval $DIALOG \ @@ -112,7 +112,8 @@ f_become_root_via_sudo() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --menu \"\$msg\" $size \ + --menu \"\$msg\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -152,11 +153,11 @@ f_become_root_via_sudo() # msg="$msg_please_enter_password" hline="$hline_alnum_punc_tab_enter" - size=$( f_dialog_inputbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "$hline" ) + f_dialog_inputbox_size height width \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$hline" # # Continue prompting until they either Cancel, succeed @@ -166,12 +167,13 @@ f_become_root_via_sudo() while [ $nfailures -lt $PASSWD_TRIES ]; do if [ "$USE_XDIALOG" ]; then password=$( $DIALOG \ - --title "$DIALOG_TITLE" \ - --backtitle "$DIALOG_BACKTITLE" \ - --hline "$hline" \ - --ok-label "$msg_ok" \ - --cancel-label "$msg_cancel" \ - --password --inputbox "$msg" $size \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --password --inputbox "$msg" \ + $height $width \ 2>&1 > /dev/null ) retval=$? @@ -187,7 +189,8 @@ f_become_root_via_sudo() --ok-label "$msg_ok" \ --cancel-label "$msg_cancel" \ --insecure \ - --passwordbox "$msg" $size \ + --passwordbox "$msg" \ + $height $width \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) retval=$? @@ -272,7 +275,7 @@ f_become_root_via_sudo() # f_authenticate_some_user() { - local msg hline size width height + local msg hline height width f_have sudo || f_die 1 "$msg_must_be_root_to_execute" "$pgm" @@ -289,14 +292,12 @@ f_authenticate_some_user() msg="$msg_please_enter_username_password" hline="$hline_alnum_punc_tab_enter" - size=$( f_xdialog_2inputsbox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "$field_username" "" \ - "$field_password" "" ) - width="${size##*[$IFS]}" - height="${size%%[$IFS]*}" + f_xdialog_2inputsbox_size height width \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$field_username" "" \ + "$field_password" "" height=$(( $height + 2 )) # Add height for --password # diff --git a/usr.sbin/bsdconfig/startup/misc b/usr.sbin/bsdconfig/startup/misc index 53ae2b0..d7560e8 100755 --- a/usr.sbin/bsdconfig/startup/misc +++ b/usr.sbin/bsdconfig/startup/misc @@ -56,7 +56,7 @@ UNAME_P=$( uname -p ) # Processor Architecture (i.e. i386) # dialog_menu_main() { - local menu_list var_list size defaultitem= + local menu_list var_list defaultitem= local hline="$hline_arrows_tab_enter" local prompt="$msg_miscellaneous_menu_text" @@ -265,12 +265,13 @@ dialog_menu_main() }' )" - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -280,7 +281,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/startup/rcadd b/usr.sbin/bsdconfig/startup/rcadd index 3a4fbaa..af3f33d 100755 --- a/usr.sbin/bsdconfig/startup/rcadd +++ b/usr.sbin/bsdconfig/startup/rcadd @@ -57,7 +57,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size + local menu_list local hline="$hline_arrows_tab_enter" local prompt="" @@ -66,12 +66,13 @@ dialog_menu_main() '2' '$msg_add_custom' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -80,7 +81,8 @@ dialog_menu_main() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/startup/rcconf b/usr.sbin/bsdconfig/startup/rcconf index 4d47ea1..82f035d 100755 --- a/usr.sbin/bsdconfig/startup/rcconf +++ b/usr.sbin/bsdconfig/startup/rcconf @@ -79,7 +79,6 @@ fi # dialog_menu_main() { - local size local hline="$hline_arrows_tab_enter" local prompt="" @@ -162,12 +161,14 @@ dialog_menu_main() set -f # noglob - size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $RCCONF_MENU_LIST ) + local height width rows + eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ + height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $RCCONF_MENU_LIST local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -180,7 +181,8 @@ dialog_menu_main() --help-label \"\$msg_details\" \ ${SHOW_DESC:+--item-help} \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $RCCONF_MENU_LIST \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/startup/rcdelete b/usr.sbin/bsdconfig/startup/rcdelete index 5a8b211..13262de 100755 --- a/usr.sbin/bsdconfig/startup/rcdelete +++ b/usr.sbin/bsdconfig/startup/rcdelete @@ -146,7 +146,6 @@ dialog_create_main() # dialog_menu_main() { - local size local hline="$hline_arrows_tab_enter" local prompt="" @@ -197,12 +196,14 @@ dialog_menu_main() set -f # noglob (descriptions in $RCCONF_MENU_LIST may contain *) - size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ + height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -216,7 +217,8 @@ dialog_menu_main() --help-label \"\$msg_details\" \ ${SHOW_DESC:+--item-help} \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -237,7 +239,6 @@ dialog_menu_main() # dialog_menu_confirm_delete() { - local size local hline="$hline_arrows_tab_enter" local prompt="$msg_are_you_sure_you_want_delete_the_following" local var_list menu_list @@ -269,12 +270,13 @@ dialog_menu_confirm_delete() }' ) - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local defaultno="defaultno" [ "$USE_XDIALOG" ] && defaultno="default-no" @@ -286,7 +288,8 @@ dialog_menu_confirm_delete() --$defaultno \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2> /dev/null diff --git a/usr.sbin/bsdconfig/startup/rcvar b/usr.sbin/bsdconfig/startup/rcvar index e82a35b..127820d 100755 --- a/usr.sbin/bsdconfig/startup/rcvar +++ b/usr.sbin/bsdconfig/startup/rcvar @@ -65,7 +65,6 @@ RCVAR_MENU_LIST= # dialog_menu_main() { - local size local hline="$hline_arrows_tab_enter" local prompt="" @@ -126,12 +125,14 @@ dialog_menu_main() set -f # noglob - size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $RCVAR_MENU_LIST ) + local height width rows + eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ + height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $RCVAR_MENU_LIST local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -143,7 +144,8 @@ dialog_menu_main() --cancel-label \"\$msg_cancel\" \ ${SHOW_DESC:+--item-help} \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $RCVAR_MENU_LIST \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/startup/share/rcconf.subr b/usr.sbin/bsdconfig/startup/share/rcconf.subr index 0e1b889..95d5107 100644 --- a/usr.sbin/bsdconfig/startup/share/rcconf.subr +++ b/usr.sbin/bsdconfig/startup/share/rcconf.subr @@ -273,7 +273,7 @@ f_startup_rcconf_map_expand() # f_dialog_input_view_details() { - local menu_list size + local menu_list local hline="$hline_arrows_tab_enter" local prompt="" @@ -301,12 +301,13 @@ f_dialog_input_view_details() '3 ($m3) $msg_show_configured' '$msg_show_configured_desc' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list f_dialog_title "$msg_choose_view_details" @@ -318,7 +319,8 @@ f_dialog_input_view_details() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -367,7 +369,6 @@ f_dialog_input_view_details() # f_dialog_input_rclist() { - local size local hline="$hline_arrows_tab_enter" local prompt="$msg_please_select_an_rcconf_directive" local menu_list @@ -414,12 +415,14 @@ f_dialog_input_rclist() set -f # noglob - size=$( eval f_dialog_menu_${SHOW_DESC:+with_help_}size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu${SHOW_DESC:+_with_help}_size \ + height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ diff --git a/usr.sbin/bsdconfig/startup/startup b/usr.sbin/bsdconfig/startup/startup index 11eb9a1..797c7ef 100755 --- a/usr.sbin/bsdconfig/startup/startup +++ b/usr.sbin/bsdconfig/startup/startup @@ -48,7 +48,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size + local menu_list local hline="$hline_arrows_tab_enter" local prompt="" @@ -59,12 +59,13 @@ dialog_menu_main() '3' '$msg_miscellaneous_startup_services' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -74,7 +75,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/timezone/share/zones.subr b/usr.sbin/bsdconfig/timezone/share/zones.subr index 3ba1d7a..0c49bc5 100644 --- a/usr.sbin/bsdconfig/timezone/share/zones.subr +++ b/usr.sbin/bsdconfig/timezone/share/zones.subr @@ -348,7 +348,7 @@ f_read_zones() f_install_zoneinfo_file() { local zoneinfo_file="$1" - local copymode title msg err size + local copymode title msg err height width if [ -L "$_PATH_LOCALTIME" ]; then copymode= @@ -374,13 +374,13 @@ f_install_zoneinfo_file() title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE" f_dialog_title_restore - size=$( f_dialog_buttonbox_size "$title" \ - "$btitle" "$msg" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$msg\" $size + f_dialog_buttonbox_size height width \ + "$title" "$btitle" "$msg" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$msg" $height $width else printf "%s\n" "$msg" fi @@ -397,15 +397,15 @@ f_install_zoneinfo_file() err=$( rm -f "$_PATH_LOCALTIME" 2>&1 ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -415,15 +415,15 @@ f_install_zoneinfo_file() err=$( rm -f "$_PATH_DB" 2>&1 ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -435,15 +435,15 @@ f_install_zoneinfo_file() msg=$( printf "$msg_removed_file" \ "$_PATH_LOCALTIME" ) if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$msg" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$msg\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$msg" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$msg" $height $width else printf "%s\n" "$msg" fi @@ -458,15 +458,15 @@ f_install_zoneinfo_file() err=$( rm -f "$_PATH_LOCALTIME" 2>&1 ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -476,15 +476,15 @@ f_install_zoneinfo_file() err=$( umask 222 && : 2>&1 > "$_PATH_LOCALTIME" ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -494,15 +494,15 @@ f_install_zoneinfo_file() err=$( cat "$zoneinfo_file" 2>&1 > "$_PATH_LOCALTIME" ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -514,15 +514,15 @@ f_install_zoneinfo_file() err=$( ( :< "$zoneinfo_file" ) 2>&1 ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -532,15 +532,15 @@ f_install_zoneinfo_file() err=$( rm -f "$_PATH_LOCALTIME" 2>&1 ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -550,15 +550,15 @@ f_install_zoneinfo_file() err=$( ln -s "$zoneinfo_file" "$_PATH_LOCALTIME" 2>&1 ) if [ "$err" ]; then if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" \ - "$btitle" \ - "$err" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$err\" $size + f_dialog_buttonbox_size height $width \ + "$title" \ + "$btitle" \ + "$err" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$err" $height $width else f_err "%s\n" "$err" fi @@ -579,13 +579,13 @@ f_install_zoneinfo_file() "$zoneinfo_file" ) fi if [ "$USEDIALOG" ]; then - size=$( f_dialog_buttonbox_size \ - "$title" "$btitle" "$msg" ) - eval $DIALOG \ - --title \"\$title\" \ - --backtitle \"\$btitle\" \ - --ok-label \"\$msg_ok\" \ - --msgbox \"\$msg\" $size + f_dialog_buttonbox_size height width \ + "$title" "$btitle" "$msg" + $DIALOG \ + --title "$title" \ + --backtitle "$btitle" \ + --ok-label "$msg_ok" \ + --msgbox "$msg" $height $width else printf "%s\n" "$msg" fi diff --git a/usr.sbin/bsdconfig/timezone/timezone b/usr.sbin/bsdconfig/timezone/timezone index 226eef7..d66428d 100755 --- a/usr.sbin/bsdconfig/timezone/timezone +++ b/usr.sbin/bsdconfig/timezone/timezone @@ -83,14 +83,14 @@ dialog_menu_main() local title="$DIALOG_TITLE" local btitle="$DIALOG_BACKTITLE" local prompt="$msg_select_region" - local size - size=$( eval f_dialog_menu_size \ - \"\$title\" \ - \"\$btitle\" \ - \"\$prompt\" \ - \"\" \ - $continent_menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$\" \ + $continent_menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -99,7 +99,8 @@ dialog_menu_main() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $continent_menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -240,7 +241,7 @@ if [ $# -ge 1 ]; then btitle="$DIALOG_BACKTITLE" f_dialog_title_restore msg=$( printf "\n$msg_use_default_zone" "$default" ) - size=$( f_dialog_buttonbox_size "$title" "$btitle" "$msg" ) + f_dialog_buttonbox_size height width "$title" "$btitle" "$msg" if [ "$USE_XDIALOG" ]; then eval $DIALOG \ @@ -248,7 +249,7 @@ if [ $# -ge 1 ]; then --backtitle \"\$btitle\" \ --ok-label \"\$msg_yes\" \ --cancel-label \"\$msg_no\" \ - --yesno \"\$msg\" $size + --yesno \"\$msg\" $height $width result=$? else eval $DIALOG \ @@ -256,7 +257,7 @@ if [ $# -ge 1 ]; then --backtitle \"\$btitle\" \ --yes-label \"\$msg_yes\" \ --no-label \"\$msg_no\" \ - --yesno \"\$msg\" $size + --yesno \"\$msg\" $height $width result=$? fi @@ -353,12 +354,12 @@ while :; do # Calculate size of menu # menu_list=$( f_continent $cont menu_list ) - size=$( eval f_dialog_menu_size \ - \"\$title\" \ - \"\$btitle\" \ - \"\$prompt\" \ - \"\" \ - $menu_list ) + eval f_dialog_menu_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\" \ + $menu_list # # Launch the country selection menu @@ -369,7 +370,8 @@ while :; do --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultctry\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -415,8 +417,8 @@ while :; do f_dialog_title_restore prompt="$msg_select_zone" menu_list=$( f_country $tlc menu_list ) - size=$( eval f_dialog_menu_size \"\$title\" \"\$btitle\" \ - \"\$prompt\" \"\" $menu_list ) + eval f_dialog_menu_size height width rows \ + \"\$title\" \"\$btitle\" \"\$prompt\" \"\" $menu_list # # Launch the zone selection menu @@ -428,7 +430,8 @@ while :; do --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultzone\" \ - --menu \"\$prompt\" $size \ + --menu \"\$prompt\" \ + $height $width $rows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/usermgmt/groupinput b/usr.sbin/bsdconfig/usermgmt/groupinput index a307a93..19b5307 100755 --- a/usr.sbin/bsdconfig/usermgmt/groupinput +++ b/usr.sbin/bsdconfig/usermgmt/groupinput @@ -221,12 +221,12 @@ while :; do " # END-QUOTE esac - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$menu_text\" \ - \"\$hline\" \ - $menu_items ) + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$menu_text\" \ + \"\$hline\" \ + $menu_items dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -235,7 +235,8 @@ while :; do --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$menu_text\" $size \ + --menu \"\$menu_text\" \ + $height $width $rows \ $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr index 78b5f80..7fc8b83 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/group_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/group_input.subr @@ -66,7 +66,7 @@ f_input_group() f_dialog_menu_group_list() { local defaultitem="$1" - local menu_list size + local menu_list local hline="$hline_alnum_punc_tab_enter" menu_list=" @@ -80,12 +80,13 @@ f_dialog_menu_group_list() }' )" - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -95,7 +96,9 @@ f_dialog_menu_group_list() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\" $size $menu_list \ + --menu \"\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? @@ -170,23 +173,25 @@ f_dialog_input_group_name() f_dialog_input_group_password() { local hline="$hline_alnum_punc_tab_enter" - local msg size rmsg rsize + local msg rmsg msg=$( printf "$msg_group_password" ) - size=$( f_dialog_inputbox_size \ + local height1 width1 + f_dialog_inputbox_size height1 width1 \ "$DIALOG_TITLE" \ "$DIALOG_BACKTITLE" \ "$msg" \ "" \ - "$hline" ) + "$hline" rmsg=$( printf "$msg_reenter_group_password" ) - rsize=$( f_dialog_inputbox_size \ + local height2 width2 + f_dialog_inputbox_size height2 width2 \ "$DIALOG_TITLE" \ "$DIALOG_BACKTITLE" \ "$rmsg" \ "" \ - "$hline" ) + "$hline" # # Loop until the user provides taint-free/valid input @@ -194,14 +199,15 @@ f_dialog_input_group_password() local retval _password1 _password2 while :; do local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --insecure \ - --passwordbox \"\$msg\" $size \ + dialog_inputbox=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$msg" \ + $height1 $width1 \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -212,14 +218,15 @@ f_dialog_input_group_password() # Return if user has either pressed ESC or chosen Cancel/No [ $retval -eq $SUCCESS ] || return $retval - dialog_inputbox=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --insecure \ - --passwordbox \"\$rmsg\" $rsize \ + dialog_inputbox=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$rmsg" \ + $height2 $width2 \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -288,7 +295,8 @@ f_dialog_input_group_gid() # f_dialog_input_group_members() { - local menu_choice msg size retval _input="$1" + local menu_choice retval _input="$1" + local msg="$msg_group_members:" local hline="$hline_num_arrows_tab_enter" local user local menu_list @@ -303,14 +311,15 @@ f_dialog_input_group_members() " # END-QUOTE local dialog_menu defaultitem= + local mheight mwidth mrows + eval f_dialog_menu_size mheight mwidth mrows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$msg\" \ + \"\$hline\" \ + $menu_list + while :; do - msg="$msg_group_members:" - menu_size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$msg\" \ - \"\$hline\" \ - $menu_list ) dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ @@ -318,7 +327,8 @@ f_dialog_input_group_members() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\$msg\" $menu_size \ + --menu \"\$msg\" \ + $mheight $mwidth $mrows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -347,12 +357,13 @@ f_dialog_input_group_members() fi done - size=$( eval f_dialog_radiolist_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\" \ - \"\$hline\" \ - $checklist_users ) + local cheight cwidth crows + eval f_dialog_checklist_size cheight cwidth crows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\" \ + \"\$hline\" \ + $checklist_users local dialog_inputbox dialog_inputbox=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -361,7 +372,8 @@ f_dialog_input_group_members() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --checklist \"\$msg\" $size \ + --checklist \"\$msg\" \ + $cheight $cwidth $crows \ $checklist_users \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr index db2c819..f088548 100644 --- a/usr.sbin/bsdconfig/usermgmt/share/user_input.subr +++ b/usr.sbin/bsdconfig/usermgmt/share/user_input.subr @@ -91,7 +91,7 @@ f_input_user() f_dialog_menu_user_list() { local defaultitem="$1" - local menu_list size + local menu_list local hline="$hline_alnum_punc_tab_enter" menu_list=" @@ -105,12 +105,13 @@ f_dialog_menu_user_list() }' )" - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\" \ - \"\$hline\" \ - $menu_list ) + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\" \ + \"\$hline\" \ + $menu_list local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -120,7 +121,9 @@ f_dialog_menu_user_list() --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$defaultitem\" \ - --menu \"\" $size $menu_list \ + --menu \"\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? @@ -142,7 +145,7 @@ f_dialog_input_member_groups() # # Loop until the user provides taint-free/valid input # - local size retval all_groups checklist_groups="" _member_groups="$1" + local retval all_groups checklist_groups="" _member_groups="$1" all_groups=$( pw groupshow -a | awk -F: ' !/^[[:space:]]*(#|$)/ { printf "%s\n", $1 @@ -157,13 +160,14 @@ f_dialog_input_member_groups() fi done + local height width rows while :; do - size=$( eval f_dialog_radiolist_size \ + eval f_dialog_checklist_size height width rows \ \"\$DIALOG_TITLE\" \ \"\$DIALOG_BACKTITLE\" \ \"\" \ \"\$hline\" \ - $checklist_groups ) + $checklist_groups local dialog_inputbox dialog_inputbox=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -172,7 +176,8 @@ f_dialog_input_member_groups() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --checklist \"\$msg\" $size \ + --checklist \"\$msg\" \ + $height $width $rows \ $checklist_groups \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -275,23 +280,25 @@ f_dialog_input_name() f_dialog_input_password() { local hline="$hline_alnum_punc_tab_enter" - local msg size rmsg rsize + local msg rmsg msg=$( printf "$msg_password" ) - size=$( f_dialog_inputbox_size \ + local height1 width1 + f_dialog_inputbox_size height1 width1 \ "$DIALOG_TITLE" \ "$DIALOG_BACKTITLE" \ "$msg" \ "" \ - "$hline" ) + "$hline" rmsg=$( printf "$msg_reenter_password" ) - rsize=$( f_dialog_inputbox_size \ + local height2 width2 + f_dialog_inputbox_size height2 width2 \ "$DIALOG_TITLE" \ "$DIALOG_BACKTITLE" \ "$rmsg" \ "" \ - "$hline" ) + "$hline" # # Loop until the user provides taint-free/valid input @@ -299,14 +306,15 @@ f_dialog_input_password() local retval _password1 _password2 while :; do local dialog_inputbox - dialog_inputbox=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --insecure \ - --passwordbox \"\$msg\" $size \ + dialog_inputbox=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$msg" \ + $height1 $width1 \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -314,17 +322,15 @@ f_dialog_input_password() setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" _password1=$( f_dialog_inputstr ) - # Return if user has either pressed ESC or chosen Cancel/No - [ $retval -eq $SUCCESS ] || return $retval - - dialog_inputbox=$( eval $DIALOG \ - --title \"\$DIALOG_TITLE\" \ - --backtitle \"\$DIALOG_BACKTITLE\" \ - --hline \"\$hline\" \ - --ok-label \"\$msg_ok\" \ - --cancel-label \"\$msg_cancel\" \ - --insecure \ - --passwordbox \"\$rmsg\" $rsize \ + dialog_inputbox=$( $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "$msg_ok" \ + --cancel-label "$msg_cancel" \ + --insecure \ + --passwordbox "$rmsg" \ + $height2 $width2 \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -463,8 +469,8 @@ f_dialog_input_class() # f_dialog_input_change() { - local calendar_size timebox_size - local msg menu_size size retval _input="$1" + local retval _input="$1" + local msg="$msg_password_expires_on" local hline="$hline_num_arrows_tab_enter" local menu_list=" @@ -474,18 +480,30 @@ f_dialog_input_change() '4' '$msg_enter_value_manually' " # END-QUOTE + local mheight mwidth mrows + eval f_dialog_menu_size mheight mwidth mrows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$msg\" \ + \"\$hline\" \ + $menu_list + local cheight cwidth + f_dialog_calendar_size cheight cwidth \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$hline" + local theight twidth + f_dialog_timebox_size theight twidth \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$hline" + # # Loop until the user provides taint-free/cancellation-free input # while :; do - msg="$msg_password_expires_on" - menu_size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$msg\" \ - \"\$hline\" \ - $menu_list ) - local dialog_menu dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -493,7 +511,8 @@ f_dialog_input_change() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --menu \"\$msg\" $menu_size \ + --menu \"\$msg\" \ + $mheight $mwidth $mrows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -517,11 +536,6 @@ f_dialog_input_change() { f_isinteger "$secs" && [ $secs -gt 0 ]; } || secs= _input_date=$( date -j -f "%s" -- "$secs" \ "+%d %m %Y" 2> /dev/null ) - calendar_size=$( f_dialog_calendar_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "$hline" ) local dialog_inputbox dialog_inputbox=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -529,7 +543,8 @@ f_dialog_input_change() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --calendar \"\$msg\" $calendar_size \ + --calendar \"\$msg\" \ + $cheight $cwidth \ $_input_date \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -544,11 +559,6 @@ f_dialog_input_change() _input_time= [ "$secs" ] && _input_time=$( date -j \ -f %s -- "$_input" "+%H %M %S" 2> /dev/null ) - timebox_size=$( f_dialog_timebox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "$hline" ) local dialog_inputbox dialog_inputbox=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -556,7 +566,8 @@ f_dialog_input_change() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --timebox \"\$msg\" $timebox_size \ + --timebox \"\$msg\" \ + $theight $twidth \ $_input_time \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -649,8 +660,8 @@ f_dialog_input_change() # f_dialog_input_expire() { - local calendar_size timebox_size - local msg menu_size size retval _input="$1" + local retval _input="$1" + local msg="$msg_account_expires_on" local hline="$hline_num_arrows_tab_enter" local menu_list=" @@ -660,18 +671,30 @@ f_dialog_input_expire() '4' '$msg_enter_value_manually' " # END-QUOTE + local mheight mwidth mrows + eval f_dialog_menu_size mheight mwidth mrows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$msg\" \ + \"\$hline\" \ + $menu_list + local cheight cwidth + f_dialog_calendar_size cheight cwidth \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$hline" + local theight twidth + f_dialog_timebox_size theight twidth \ + "$DIALOG_TITLE" \ + "$DIALOG_BACKTITLE" \ + "$msg" \ + "$hline" + # # Loop until the user provides taint-free/cancellation-free input # while :; do - msg="$msg_account_expires_on" - menu_size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$msg\" \ - \"\$hline\" \ - $menu_list ) - local dialog_menu dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -679,7 +702,8 @@ f_dialog_input_expire() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --menu \"\$msg\" $menu_size \ + --menu \"\$msg\" \ + $mheight $mwidth $mrows \ $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -703,11 +727,6 @@ f_dialog_input_expire() { f_isinteger "$secs" && [ $secs -gt 0 ]; } || secs= _input_date=$( date -j -f "%s" -- "$secs" \ "+%d %m %Y" 2> /dev/null ) - calendar_size=$( f_dialog_calendar_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "$hline" ) local dialog_inputbox dialog_inputbox=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -715,7 +734,8 @@ f_dialog_input_expire() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --calendar \"\$msg\" $calendar_size \ + --calendar \"\$msg\" \ + $cheight $cwidth \ $_input_date \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -730,18 +750,14 @@ f_dialog_input_expire() _input_time= [ "$secs" ] && _input_time=$( date -j \ -f %s -- "$_input" "+%H %M %S" 2> /dev/null ) - timebox_size=$( f_dialog_timebox_size \ - "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" \ - "$msg" \ - "$hline" ) dialog_inputbox=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ --backtitle \"\$DIALOG_BACKTITLE\" \ --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --timebox \"\$msg\" $timebox_size \ + --timebox \"\$msg\" \ + $theight $twidth \ $_input_time \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) @@ -982,7 +998,7 @@ f_dialog_input_dotfiles_create() # f_dialog_input_shell() { - local size retval shells shell_list _input="$1" + local retval shells shell_list _input="$1" local hline="$hline_arrows_space_tab_enter" local prompt="$msg_select_login_shell" @@ -997,12 +1013,13 @@ f_dialog_input_shell() done ) - size=$( eval f_dialog_radiolist_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$prompt\" \ - \"\$hline\" \ - $shell_list ) + local height width rows + eval f_dialog_radiolist_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$prompt\" \ + \"\$hline\" \ + $shell_list local dialog_inputbox dialog_inputbox=$( eval $DIALOG \ @@ -1011,7 +1028,8 @@ f_dialog_input_shell() --hline \"\$hline\" \ --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ - --radiolist \"\$prompt\" $size \ + --radiolist \"\$prompt\" \ + $height $width $rows \ $shell_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/usermgmt/userinput b/usr.sbin/bsdconfig/usermgmt/userinput index ed7e841..2f9a58e 100755 --- a/usr.sbin/bsdconfig/usermgmt/userinput +++ b/usr.sbin/bsdconfig/usermgmt/userinput @@ -384,12 +384,12 @@ while :; do ;; esac - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\$menu_text\" \ - \"\$hline\" \ - $menu_items ) + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\$menu_text\" \ + \"\$hline\" \ + $menu_items dialog_menu=$( eval $DIALOG \ --title \"\$DIALOG_TITLE\" \ @@ -398,7 +398,8 @@ while :; do --ok-label \"\$msg_ok\" \ --cancel-label \"\$msg_cancel\" \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\$menu_text\" $size \ + --menu \"\$menu_text\" \ + $height $width $rows \ $menu_items \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) diff --git a/usr.sbin/bsdconfig/usermgmt/usermgmt b/usr.sbin/bsdconfig/usermgmt/usermgmt index 06144e1..8ea5ae2 100755 --- a/usr.sbin/bsdconfig/usermgmt/usermgmt +++ b/usr.sbin/bsdconfig/usermgmt/usermgmt @@ -51,7 +51,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) # dialog_menu_main() { - local menu_list size + local menu_list local hline="$hline_arrows_tab_enter" menu_list=" @@ -65,20 +65,16 @@ dialog_menu_main() '6' '$msg_delete_group' " # END-QUOTE - size=$( eval f_dialog_menu_size \ - \"\$DIALOG_TITLE\" \ - \"\$DIALOG_BACKTITLE\" \ - \"\" \ - \"\$hline\" \ - $menu_list ) - - if [ "$USE_XDIALOG" ]; then - # need to bump the width for the buttons - local height menu_height - height="${size%%[$IFS]*}" # first word - menu_height="${size##*[$IFS]}" # last word - size="$height 40 $menu_height" - fi + local height width rows + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \ + \"\$DIALOG_BACKTITLE\" \ + \"\" \ + \"\$hline\" \ + $menu_list + + # When using Xdialog(1) we need to bump the width for the buttons + [ "$USE_XDIALOG" ] && width=40 local dialog_menu dialog_menu=$( eval $DIALOG \ @@ -91,7 +87,9 @@ dialog_menu_main() --help-label \"\$msg_help\" \ ${USE_XDIALOG:+--help \"\"} \ --default-item \"\$DEFAULTITEM_$$\" \ - --menu \"\" $size $menu_list \ + --menu \"\" \ + $height $width $rows \ + $menu_list \ 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) local retval=$? |