1252995Sdteskeif [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1 2252995Sdteske# 3263791Sdteske# Copyright (c) 2006-2014 Devin Teske 4252995Sdteske# All rights reserved. 5252995Sdteske# 6252995Sdteske# Redistribution and use in source and binary forms, with or without 7252995Sdteske# modification, are permitted provided that the following conditions 8252995Sdteske# are met: 9252995Sdteske# 1. Redistributions of source code must retain the above copyright 10252995Sdteske# notice, this list of conditions and the following disclaimer. 11252995Sdteske# 2. Redistributions in binary form must reproduce the above copyright 12252995Sdteske# notice, this list of conditions and the following disclaimer in the 13252995Sdteske# documentation and/or other materials provided with the distribution. 14252995Sdteske# 15252995Sdteske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16252995Sdteske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17252995Sdteske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18252995Sdteske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19252995Sdteske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20252995Sdteske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21252995Sdteske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22252995Sdteske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23252995Sdteske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24252995Sdteske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25252995Sdteske# SUCH DAMAGE. 26252995Sdteske# 27252995Sdteske# $FreeBSD$ 28252995Sdteske# 29252995Sdteske############################################################ INCLUDES 30252995Sdteske 31252995SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 32252995Sdteske. $BSDCFG_SHARE/common.subr || exit 1 33252995Sdteskef_dprintf "%s: loading includes..." dialog.subr 34252995Sdteskef_include $BSDCFG_SHARE/strings.subr 35252995Sdteskef_include $BSDCFG_SHARE/variable.subr 36252995Sdteske 37252995SdteskeBSDCFG_LIBE="/usr/libexec/bsdconfig" 38252995Sdteskef_include_lang $BSDCFG_LIBE/include/messages.subr 39252995Sdteske 40252995Sdteske############################################################ CONFIGURATION 41252995Sdteske 42252995Sdteske# 43252995Sdteske# Default file descriptor to link to stdout for dialog(1) passthru allowing 44252995Sdteske# execution of dialog from within a sub-shell (so-long as its standard output 45252995Sdteske# is explicitly redirected to this file descriptor). 46252995Sdteske# 47252995Sdteske: ${DIALOG_TERMINAL_PASSTHRU_FD:=${TERMINAL_STDOUT_PASSTHRU:-3}} 48252995Sdteske 49252995Sdteske############################################################ GLOBALS 50252995Sdteske 51252995Sdteske# 52252995Sdteske# Default name of dialog(1) utility 53252995Sdteske# NOTE: This is changed to "Xdialog" by the optional `-X' argument 54252995Sdteske# 55252995SdteskeDIALOG="dialog" 56252995Sdteske 57252995Sdteske# 58252995Sdteske# Default dialog(1) title and backtitle text 59252995Sdteske# 60252995SdteskeDIALOG_TITLE="$pgm" 61252995SdteskeDIALOG_BACKTITLE="bsdconfig" 62252995Sdteske 63252995Sdteske# 64252995Sdteske# Settings used while interacting with dialog(1) 65252995Sdteske# 66252995SdteskeDIALOG_MENU_TAGS="123456789ABCDEFGHIJKLMNOPQRSTUVWYZabcdefghijklmnopqrstuvwxyz" 67252995Sdteske 68252995Sdteske# 69252995Sdteske# Declare that we are fully-compliant with Xdialog(1) by unset'ing all 70252995Sdteske# compatibility settings. 71252995Sdteske# 72252995Sdteskeunset XDIALOG_HIGH_DIALOG_COMPAT 73252995Sdteskeunset XDIALOG_FORCE_AUTOSIZE 74252995Sdteskeunset XDIALOG_INFOBOX_TIMEOUT 75252995Sdteske 76252995Sdteske# 77263791Sdteske# Exit codes for [X]dialog(1) 78263791Sdteske# 79263791SdteskeDIALOG_OK=${SUCCESS:-0} 80263791SdteskeDIALOG_CANCEL=${FAILURE:-1} 81263791SdteskeDIALOG_HELP=2 82263791SdteskeDIALOG_ITEM_HELP=2 83263791SdteskeDIALOG_EXTRA=3 84263791SdteskeDIALOG_ITEM_HELP=4 85263791Sdteskeexport DIALOG_ERROR=254 # sh(1) can't handle the default of `-1' 86263791SdteskeDIALOG_ESC=255 87263791Sdteske 88263791Sdteske# 89252995Sdteske# Default behavior is to call f_dialog_init() automatically when loaded. 90252995Sdteske# 91252995Sdteske: ${DIALOG_SELF_INITIALIZE=1} 92252995Sdteske 93252995Sdteske# 94252995Sdteske# Default terminal size (used if/when running without a controlling terminal) 95252995Sdteske# 96252995Sdteske: ${DEFAULT_TERMINAL_SIZE:=24 80} 97252995Sdteske 98252995Sdteske# 99252995Sdteske# Minimum width(s) for various dialog(1) implementations (sensible global 100252995Sdteske# default(s) for all widgets of a given variant) 101252995Sdteske# 102252995Sdteske: ${DIALOG_MIN_WIDTH:=24} 103252995Sdteske: ${XDIALOG_MIN_WIDTH:=35} 104252995Sdteske 105252995Sdteske# 106252995Sdteske# When manually sizing Xdialog(1) widgets such as calendar and timebox, you'll 107252995Sdteske# need to know the size of the embedded GUI objects because the height passed 108252995Sdteske# to Xdialog(1) for these widgets has to be tall enough to accomodate them. 109252995Sdteske# 110252995Sdteske# These values are helpful when manually sizing with dialog(1) too, but in a 111252995Sdteske# different way. dialog(1) does not make you accomodate the custom items in the 112252995Sdteske# height (but does for width) -- a height of 3 will display three lines and a 113252995Sdteske# full calendar, for example (whereas Xdialog will truncate the calendar if 114252995Sdteske# given a height of 3). For dialog(1), use these values for making sure that 115252995Sdteske# the height does not exceed max_height (obtained by f_dialog_max_size()). 116252995Sdteske# 117252995SdteskeDIALOG_CALENDAR_HEIGHT=15 118252995SdteskeDIALOG_TIMEBOX_HEIGHT=6 119252995Sdteske 120252995Sdteske############################################################ GENERIC FUNCTIONS 121252995Sdteske 122252995Sdteske# f_dialog_data_sanitize $var_to_edit ... 123252995Sdteske# 124252995Sdteske# When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors 125252995Sdteske# are generated from underlying libraries. For example, if $LANG is set to an 126252995Sdteske# invalid or unknown locale, the warnings from the Xdialog(1) libraries will 127252995Sdteske# clutter the output. This function helps by providing a centralied function 128252995Sdteske# that removes spurious warnings from the dialog(1) (or Xdialog(1)) response. 129252995Sdteske# 130252995Sdteske# Simply pass the name of one or more variables that need to be sanitized. 131252995Sdteske# After execution, the variables will hold their newly-sanitized data. 132252995Sdteske# 133252995Sdteskef_dialog_data_sanitize() 134252995Sdteske{ 135252995Sdteske if [ "$#" -eq 0 ]; then 136252995Sdteske f_dprintf "%s: called with zero arguments" \ 137252995Sdteske f_dialog_response_sanitize 138252995Sdteske return $FAILURE 139252995Sdteske fi 140252995Sdteske 141252995Sdteske local __var_to_edit 142252995Sdteske for __var_to_edit in $*; do 143252995Sdteske # Skip warnings and trim leading/trailing whitespace 144252995Sdteske setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk ' 145252995Sdteske BEGIN { data = 0 } 146252995Sdteske { 147252995Sdteske if ( ! data ) 148252995Sdteske { 149252995Sdteske if ( $0 ~ /^$/ ) next 150252995Sdteske if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next 151252995Sdteske data = 1 152252995Sdteske } 153252995Sdteske print 154252995Sdteske } 155252995Sdteske ' )" 156252995Sdteske done 157252995Sdteske} 158252995Sdteske 159252995Sdteske# f_dialog_line_sanitize $var_to_edit ... 160252995Sdteske# 161252995Sdteske# When using dialog(1) or Xdialog(1) sometimes unintended warnings or errors 162252995Sdteske# are generated from underlying libraries. For example, if $LANG is set to an 163252995Sdteske# invalid or unknown locale, the warnings from the Xdialog(1) libraries will 164252995Sdteske# clutter the output. This function helps by providing a centralied function 165252995Sdteske# that removes spurious warnings from the dialog(1) (or Xdialog(1)) response. 166252995Sdteske# 167252995Sdteske# Simply pass the name of one or more variables that need to be sanitized. 168252995Sdteske# After execution, the variables will hold their newly-sanitized data. 169252995Sdteske# 170252995Sdteske# This function, unlike f_dialog_data_sanitize(), also removes leading/trailing 171252995Sdteske# whitespace from each line. 172252995Sdteske# 173252995Sdteskef_dialog_line_sanitize() 174252995Sdteske{ 175252995Sdteske if [ "$#" -eq 0 ]; then 176252995Sdteske f_dprintf "%s: called with zero arguments" \ 177252995Sdteske f_dialog_response_sanitize 178252995Sdteske return $FAILURE 179252995Sdteske fi 180252995Sdteske 181252995Sdteske local __var_to_edit 182252995Sdteske for __var_to_edit in $*; do 183252995Sdteske # Skip warnings and trim leading/trailing whitespace 184252995Sdteske setvar $__var_to_edit "$( f_getvar $__var_to_edit | awk ' 185252995Sdteske BEGIN { data = 0 } 186252995Sdteske { 187252995Sdteske if ( ! data ) 188252995Sdteske { 189252995Sdteske if ( $0 ~ /^$/ ) next 190252995Sdteske if ( $0 ~ /^Gdk-WARNING \*\*:/ ) next 191252995Sdteske data = 1 192252995Sdteske } 193252995Sdteske sub(/^[[:space:]]*/, "") 194252995Sdteske sub(/[[:space:]]*$/, "") 195252995Sdteske print 196252995Sdteske } 197252995Sdteske ' )" 198252995Sdteske done 199252995Sdteske} 200252995Sdteske 201252995Sdteske############################################################ TITLE FUNCTIONS 202252995Sdteske 203252995Sdteske# f_dialog_title [$new_title] 204252995Sdteske# 205252995Sdteske# Set the title of future dialog(1) ($DIALOG_TITLE) or backtitle of Xdialog(1) 206252995Sdteske# ($DIALOG_BACKTITLE) invocations. If no arguments are given or the first 207252995Sdteske# argument is NULL, the current title is returned. 208252995Sdteske# 209252995Sdteske# Each time this function is called, a backup of the current values is made 210253168Sdteske# allowing a one-time (single-level) restoration of the previous title using 211253168Sdteske# the f_dialog_title_restore() function (below). 212252995Sdteske# 213252995Sdteskef_dialog_title() 214252995Sdteske{ 215252995Sdteske local new_title="$1" 216252995Sdteske 217252995Sdteske if [ "${1+set}" ]; then 218252995Sdteske if [ "$USE_XDIALOG" ]; then 219252995Sdteske _DIALOG_BACKTITLE="$DIALOG_BACKTITLE" 220252995Sdteske DIALOG_BACKTITLE="$new_title" 221252995Sdteske else 222252995Sdteske _DIALOG_TITLE="$DIALOG_TITLE" 223252995Sdteske DIALOG_TITLE="$new_title" 224252995Sdteske fi 225252995Sdteske else 226252995Sdteske if [ "$USE_XDIALOG" ]; then 227252995Sdteske echo "$DIALOG_BACKTITLE" 228252995Sdteske else 229252995Sdteske echo "$DIALOG_TITLE" 230252995Sdteske fi 231252995Sdteske fi 232252995Sdteske} 233252995Sdteske 234252995Sdteske# f_dialog_title_restore 235252995Sdteske# 236252995Sdteske# Restore the previous title set by the last call to f_dialog_title(). 237252995Sdteske# Restoration is non-recursive and only works to restore the most-recent title. 238252995Sdteske# 239252995Sdteskef_dialog_title_restore() 240252995Sdteske{ 241252995Sdteske if [ "$USE_XDIALOG" ]; then 242252995Sdteske DIALOG_BACKTITLE="$_DIALOG_BACKTITLE" 243252995Sdteske else 244252995Sdteske DIALOG_TITLE="$_DIALOG_TITLE" 245252995Sdteske fi 246252995Sdteske} 247252995Sdteske 248252995Sdteske# f_dialog_backtitle [$new_backtitle] 249252995Sdteske# 250252995Sdteske# Set the backtitle of future dialog(1) ($DIALOG_BACKTITLE) or title of 251252995Sdteske# Xdialog(1) ($DIALOG_TITLE) invocations. If no arguments are given or the 252252995Sdteske# first argument is NULL, the current backtitle is returned. 253252995Sdteske# 254252995Sdteskef_dialog_backtitle() 255252995Sdteske{ 256252995Sdteske local new_backtitle="$1" 257252995Sdteske 258252995Sdteske if [ "${1+set}" ]; then 259252995Sdteske if [ "$USE_XDIALOG" ]; then 260252995Sdteske _DIALOG_TITLE="$DIALOG_TITLE" 261252995Sdteske DIALOG_TITLE="$new_backtitle" 262252995Sdteske else 263252995Sdteske _DIALOG_BACKTITLE="$DIALOG_BACKTITLE" 264252995Sdteske DIALOG_BACKTITLE="$new_backtitle" 265252995Sdteske fi 266252995Sdteske else 267252995Sdteske if [ "$USE_XDIALOG" ]; then 268252995Sdteske echo "$DIALOG_TITLE" 269252995Sdteske else 270252995Sdteske echo "$DIALOG_BACKTITLE" 271252995Sdteske fi 272252995Sdteske fi 273252995Sdteske} 274252995Sdteske 275252995Sdteske# f_dialog_backtitle_restore 276252995Sdteske# 277252995Sdteske# Restore the previous backtitle set by the last call to f_dialog_backtitle(). 278252995Sdteske# Restoration is non-recursive and only works to restore the most-recent 279252995Sdteske# backtitle. 280252995Sdteske# 281252995Sdteskef_dialog_backtitle_restore() 282252995Sdteske{ 283252995Sdteske if [ "$USE_XDIALOG" ]; then 284252995Sdteske DIALOG_TITLE="$_DIALOG_TITLE" 285252995Sdteske else 286252995Sdteske DIALOG_BACKTITLE="$_DIALOG_BACKTITLE" 287252995Sdteske fi 288252995Sdteske} 289252995Sdteske 290252995Sdteske############################################################ SIZE FUNCTIONS 291252995Sdteske 292252995Sdteske# f_dialog_max_size $var_height $var_width 293252995Sdteske# 294252995Sdteske# Get the maximum height and width for a dialog widget and store the values in 295252995Sdteske# $var_height and $var_width (respectively). 296252995Sdteske# 297252995Sdteskef_dialog_max_size() 298252995Sdteske{ 299263791Sdteske local funcname=f_dialog_max_size 300252995Sdteske local __var_height="$1" __var_width="$2" __max_size 301252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 302252995Sdteske if [ "$USE_XDIALOG" ]; then 303252995Sdteske __max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION 304252995Sdteske else 305263791Sdteske if __max_size=$( $DIALOG --print-maxsize \ 306263791Sdteske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) 307263791Sdteske then 308263791Sdteske f_dprintf "$funcname: %s --print-maxsize = [%s]" \ 309263791Sdteske "$DIALOG" "$__max_size" 310263791Sdteske # usually "MaxSize: 24, 80" 311263791Sdteske __max_size="${__max_size#*: }" 312263791Sdteske f_replaceall "$__max_size" "," "" __max_size 313263791Sdteske else 314263791Sdteske f_eval_catch -dk __max_size $funcname stty \ 315263791Sdteske 'stty size' || __max_size= 316263791Sdteske # usually "24 80" 317263791Sdteske fi 318252995Sdteske : ${__max_size:=$DEFAULT_TERMINAL_SIZE} 319252995Sdteske fi 320253169Sdteske if [ "$__var_height" ]; then 321253169Sdteske local __height="${__max_size%%[$IFS]*}" 322253169Sdteske # 323253169Sdteske # If we're not using Xdialog(1), we should assume that $DIALOG 324253169Sdteske # will render --backtitle behind the widget. In such a case, we 325253169Sdteske # should prevent a widget from obscuring the backtitle (unless 326253169Sdteske # $NO_BACKTITLE is set and non-NULL, allowing a trap-door). 327253169Sdteske # 328253169Sdteske if [ ! "$USE_XDIALOG" ] && [ ! "$NO_BACKTITLE" ]; then 329253169Sdteske # 330253169Sdteske # If use_shadow (in ~/.dialogrc) is OFF, we need to 331253169Sdteske # subtract 4, otherwise 5. However, don't check this 332253169Sdteske # every time, rely on an initialization variable set 333253169Sdteske # by f_dialog_init(). 334253169Sdteske # 335253169Sdteske local __adjust=5 336253169Sdteske [ "$NO_SHADOW" ] && __adjust=4 337253169Sdteske 338253169Sdteske # Don't adjust height if already too small (allowing 339253169Sdteske # obscured backtitle for small values of __height). 340253169Sdteske [ ${__height:-0} -gt 11 ] && 341253169Sdteske __height=$(( $__height - $__adjust )) 342253169Sdteske fi 343253169Sdteske setvar "$__var_height" "$__height" 344253169Sdteske fi 345252995Sdteske [ "$__var_width" ] && setvar "$__var_width" "${__max_size##*[$IFS]}" 346252995Sdteske} 347252995Sdteske 348252995Sdteske# f_dialog_size_constrain $var_height $var_width [$min_height [$min_width]] 349252995Sdteske# 350252995Sdteske# Modify $var_height to be no-less-than $min_height (if given; zero otherwise) 351252995Sdteske# and no-greater-than terminal height (or screen height if $USE_XDIALOG is 352252995Sdteske# set). 353252995Sdteske# 354252995Sdteske# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or 355252995Sdteske# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal 356252995Sdteske# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by 357252995Sdteske# passing $min_width. 358252995Sdteske# 359252995Sdteske# Return status is success unless one of the passed arguments is invalid 360252995Sdteske# or all of the $var_* arguments are either NULL or missing. 361252995Sdteske# 362252995Sdteskef_dialog_size_constrain() 363252995Sdteske{ 364252995Sdteske local __var_height="$1" __var_width="$2" 365252995Sdteske local __min_height="$3" __min_width="$4" 366252995Sdteske local __retval=$SUCCESS 367252995Sdteske 368252995Sdteske # Return failure unless at least one var_* argument is passed 369252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 370252995Sdteske 371252995Sdteske # 372252995Sdteske # Print debug warnings if any given (non-NULL) argument are invalid 373252995Sdteske # NOTE: Don't change the name of $__{var,min,}{height,width} 374252995Sdteske # 375252995Sdteske local __height __width 376252995Sdteske local __arg __cp __fname=f_dialog_size_constrain 377252995Sdteske for __arg in height width; do 378252995Sdteske debug= f_getvar __var_$__arg __cp 379252995Sdteske [ "$__cp" ] || continue 380252995Sdteske if ! debug= f_getvar "$__cp" __$__arg; then 381252995Sdteske f_dprintf "%s: var_%s variable \`%s' not set" \ 382252995Sdteske $__fname $__arg "$__cp" 383252995Sdteske __retval=$FAILURE 384252995Sdteske elif ! eval f_isinteger \$__$__arg; then 385252995Sdteske f_dprintf "%s: var_%s variable value not a number" \ 386252995Sdteske $__fname $__arg 387252995Sdteske __retval=$FAILURE 388252995Sdteske fi 389252995Sdteske done 390252995Sdteske for __arg in height width; do 391252995Sdteske debug= f_getvar __min_$__arg __cp 392252995Sdteske [ "$__cp" ] || continue 393252995Sdteske f_isinteger "$__cp" && continue 394252995Sdteske f_dprintf "%s: min_%s value not a number" $__fname $__arg 395252995Sdteske __retval=$FAILURE 396252995Sdteske setvar __min_$__arg "" 397252995Sdteske done 398252995Sdteske 399252995Sdteske # Obtain maximum height and width values 400252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 401252995Sdteske # from becoming local (and thus preventing setvar from working). 402252995Sdteske local __max_height_size_constain __max_width_size_constrain 403252995Sdteske f_dialog_max_size \ 404252995Sdteske __max_height_size_constrain __max_width_size_constrain 405252995Sdteske 406252995Sdteske # Adjust height if desired 407252995Sdteske if [ "$__var_height" ]; then 408252995Sdteske if [ $__height -lt ${__min_height:-0} ]; then 409252995Sdteske setvar "$__var_height" $__min_height 410252995Sdteske elif [ $__height -gt $__max_height_size_constrain ]; then 411252995Sdteske setvar "$__var_height" $__max_height_size_constrain 412252995Sdteske fi 413252995Sdteske fi 414252995Sdteske 415252995Sdteske # Adjust width if desired 416252995Sdteske if [ "$__var_width" ]; then 417252995Sdteske if [ "$USE_XDIALOG" ]; then 418252995Sdteske : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} 419252995Sdteske else 420252995Sdteske : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} 421252995Sdteske fi 422252995Sdteske if [ $__width -lt $__min_width ]; then 423252995Sdteske setvar "$__var_width" $__min_width 424252995Sdteske elif [ $__width -gt $__max_width_size_constrain ]; then 425252995Sdteske setvar "$__var_width" $__max_width_size_constrain 426252995Sdteske fi 427252995Sdteske fi 428252995Sdteske 429252995Sdteske if [ "$debug" ]; then 430252995Sdteske # Print final constrained values to debugging 431263791Sdteske [ "$__var_height" ] && f_quietly f_getvar "$__var_height" 432263791Sdteske [ "$__var_width" ] && f_quietly f_getvar "$__var_width" 433252995Sdteske fi 434252995Sdteske 435252995Sdteske return $__retval # success if no debug warnings were printed 436252995Sdteske} 437252995Sdteske 438252995Sdteske# f_dialog_menu_constrain $var_height $var_width $var_rows "$prompt" \ 439252995Sdteske# [$min_height [$min_width [$min_rows]]] 440252995Sdteske# 441252995Sdteske# Modify $var_height to be no-less-than $min_height (if given; zero otherwise) 442252995Sdteske# and no-greater-than terminal height (or screen height if $USE_XDIALOG is 443252995Sdteske# set). 444252995Sdteske# 445252995Sdteske# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or 446252995Sdteske# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal 447252995Sdteske# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by 448252995Sdteske# passing $min_width. 449252995Sdteske# 450252995Sdteske# Last, modify $var_rows to be no-less-than $min_rows (if specified; zero 451252995Sdteske# otherwise) and no-greater-than (max_height - 8) where max_height is the 452252995Sdteske# terminal height (or screen height if $USE_XDIALOG is set). If $prompt is NULL 453252995Sdteske# or missing, dialog(1) allows $var_rows to be (max_height - 7), maximizing the 454252995Sdteske# number of visible rows. 455252995Sdteske# 456252995Sdteske# Return status is success unless one of the passed arguments is invalid 457252995Sdteske# or all of the $var_* arguments are either NULL or missing. 458252995Sdteske# 459252995Sdteskef_dialog_menu_constrain() 460252995Sdteske{ 461252995Sdteske local __var_height="$1" __var_width="$2" __var_rows="$3" __prompt="$4" 462252995Sdteske local __min_height="$5" __min_width="$6" __min_rows="$7" 463252995Sdteske 464252995Sdteske # Return failure unless at least one var_* argument is passed 465252995Sdteske [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || 466252995Sdteske return $FAILURE 467252995Sdteske 468252995Sdteske # 469252995Sdteske # Print debug warnings if any given (non-NULL) argument are invalid 470252995Sdteske # NOTE: Don't change the name of $__{var,min,}{height,width,rows} 471252995Sdteske # 472263791Sdteske local __height_menu_constrain __width_menu_constrain 473263791Sdteske local __rows_menu_constrain 474252995Sdteske local __arg __cp __fname=f_dialog_menu_constrain 475252995Sdteske for __arg in height width rows; do 476252995Sdteske debug= f_getvar __var_$__arg __cp 477252995Sdteske [ "$__cp" ] || continue 478263791Sdteske if ! debug= f_getvar "$__cp" __${__arg}_menu_constrain; then 479252995Sdteske f_dprintf "%s: var_%s variable \`%s' not set" \ 480252995Sdteske $__fname $__arg "$__cp" 481252995Sdteske __retval=$FAILURE 482263791Sdteske elif ! eval f_isinteger \$__${__arg}_menu_constrain; then 483252995Sdteske f_dprintf "%s: var_%s variable value not a number" \ 484252995Sdteske $__fname $__arg 485252995Sdteske __retval=$FAILURE 486252995Sdteske fi 487252995Sdteske done 488252995Sdteske for __arg in height width rows; do 489252995Sdteske debug= f_getvar __min_$__arg __cp 490252995Sdteske [ "$__cp" ] || continue 491252995Sdteske f_isinteger "$__cp" && continue 492252995Sdteske f_dprintf "%s: min_%s value not a number" $__fname $__arg 493252995Sdteske __retval=$FAILURE 494252995Sdteske setvar __min_$__arg "" 495252995Sdteske done 496252995Sdteske 497252995Sdteske # Obtain maximum height and width values 498252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 499252995Sdteske # from becoming local (and thus preventing setvar from working). 500252995Sdteske local __max_height_menu_constrain __max_width_menu_constrain 501252995Sdteske f_dialog_max_size \ 502252995Sdteske __max_height_menu_constrain __max_width_menu_constrain 503252995Sdteske 504252995Sdteske # Adjust height if desired 505252995Sdteske if [ "$__var_height" ]; then 506263791Sdteske if [ $__height_menu_constrain -lt ${__min_height:-0} ]; then 507252995Sdteske setvar "$__var_height" $__min_height 508263791Sdteske elif [ $__height_menu_constrain -gt \ 509263791Sdteske $__max_height_menu_constrain ] 510263791Sdteske then 511252995Sdteske setvar "$__var_height" $__max_height_menu_constrain 512252995Sdteske fi 513252995Sdteske fi 514252995Sdteske 515252995Sdteske # Adjust width if desired 516252995Sdteske if [ "$__var_width" ]; then 517252995Sdteske if [ "$USE_XDIALOG" ]; then 518252995Sdteske : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}} 519252995Sdteske else 520252995Sdteske : ${__min_width:=${DIALOG_MIN_WIDTH:-24}} 521252995Sdteske fi 522263791Sdteske if [ $__width_menu_constrain -lt $__min_width ]; then 523252995Sdteske setvar "$__var_width" $__min_width 524263791Sdteske elif [ $__width_menu_constrain -gt \ 525263791Sdteske $__max_width_menu_constrain ] 526263791Sdteske then 527252995Sdteske setvar "$__var_width" $__max_width_menu_constrain 528252995Sdteske fi 529252995Sdteske fi 530252995Sdteske 531252995Sdteske # Adjust rows if desired 532252995Sdteske if [ "$__var_rows" ]; then 533252995Sdteske if [ "$USE_XDIALOG" ]; then 534252995Sdteske : ${__min_rows:=1} 535252995Sdteske else 536252995Sdteske : ${__min_rows:=0} 537252995Sdteske fi 538252995Sdteske 539263791Sdteske local __max_rows_menu_constrain=$(( 540263791Sdteske $__max_height_menu_constrain - 7 541263791Sdteske )) 542252995Sdteske # If prompt_len is zero (no prompt), bump the max-rows by 1 543252995Sdteske # Default assumption is (if no argument) that there's no prompt 544263791Sdteske [ ${__prompt_len:-0} -gt 0 ] || __max_rows_menu_constrain=$(( 545263791Sdteske $__max_rows_menu_constrain + 1 546263791Sdteske )) 547252995Sdteske 548263791Sdteske if [ $__rows_menu_constrain -lt $__min_rows ]; then 549252995Sdteske setvar "$__var_rows" $__min_rows 550263791Sdteske elif [ $__rows_menu_constrain -gt $__max_rows_menu_constrain ] 551263791Sdteske then 552263791Sdteske setvar "$__var_rows" $__max_rows_menu_constrain 553252995Sdteske fi 554252995Sdteske fi 555252995Sdteske 556252995Sdteske if [ "$debug" ]; then 557263791Sdteske # Print final constrained values to debugging 558263791Sdteske [ "$__var_height" ] && f_quietly f_getvar "$__var_height" 559263791Sdteske [ "$__var_width" ] && f_quietly f_getvar "$__var_width" 560263791Sdteske [ "$__var_rows" ] && f_quietly f_getvar "$__var_rows" 561252995Sdteske fi 562252995Sdteske 563252995Sdteske return $__retval # success if no debug warnings were printed 564252995Sdteske} 565252995Sdteske 566252995Sdteske# f_dialog_infobox_size [-n] $var_height $var_width \ 567252995Sdteske# $title $backtitle $prompt [$hline] 568252995Sdteske# 569252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 570252995Sdteske# `--infobox' boxes sensibly. 571252995Sdteske# 572252995Sdteske# This function helps solve this issue by taking two sets of sequential 573252995Sdteske# arguments. The first set of arguments are the variable names to use when 574252995Sdteske# storing the calculated height and width. The second set of arguments are the 575252995Sdteske# title, backtitle, prompt, and [optionally] hline. The optimal height and 576252995Sdteske# width for the described widget (not exceeding the actual terminal height or 577252995Sdteske# width) is stored in $var_height and $var_width (respectively). 578252995Sdteske# 579252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height and 580252995Sdteske# $var_width) are not constrained to minimum/maximum values. 581252995Sdteske# 582252995Sdteske# Newline character sequences (``\n'') in $prompt are expanded as-is done by 583252995Sdteske# dialog(1). 584252995Sdteske# 585252995Sdteskef_dialog_infobox_size() 586252995Sdteske{ 587252995Sdteske local __constrain=1 588252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 589252995Sdteske local __var_height="$1" __var_width="$2" 590252995Sdteske local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" 591252995Sdteske 592252995Sdteske # Return unless at least one size aspect has been requested 593252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 594252995Sdteske 595252995Sdteske # Default height/width of zero for auto-sizing 596252995Sdteske local __height=0 __width=0 __n 597252995Sdteske 598252995Sdteske # Adjust height if desired 599252995Sdteske if [ "$__var_height" ]; then 600252995Sdteske # 601252995Sdteske # Set height based on number of rows in prompt 602252995Sdteske # 603252995Sdteske __n=$( echo -n "$__prompt" | f_number_of_lines ) 604252995Sdteske __n=$(( $__n + 2 )) 605252995Sdteske [ $__n -gt $__height ] && __height=$__n 606252995Sdteske 607252995Sdteske # 608252995Sdteske # For Xdialog(1) bump height if backtitle is enabled (displayed 609252995Sdteske # in the X11 window with a separator line between the backtitle 610252995Sdteske # and msg text). 611252995Sdteske # 612252995Sdteske if [ "$USE_XDIALOG" -a "$__btitle" ]; then 613252995Sdteske __n=$( echo "$__btitle" | f_number_of_lines ) 614252995Sdteske __height=$(( $__height + $__n + 2 )) 615252995Sdteske fi 616252995Sdteske 617252995Sdteske setvar "$__var_height" $__height 618252995Sdteske fi 619252995Sdteske 620252995Sdteske # Adjust width if desired 621252995Sdteske if [ "$__var_width" ]; then 622252995Sdteske # 623252995Sdteske # Bump width for long titles 624252995Sdteske # 625252995Sdteske __n=$(( ${#__title} + 4 )) 626252995Sdteske [ $__n -gt $__width ] && __width=$__n 627252995Sdteske 628252995Sdteske # 629252995Sdteske # If using Xdialog(1), bump width for long backtitles (which 630252995Sdteske # appear within the window). 631252995Sdteske # 632252995Sdteske if [ "$USE_XDIALOG" ]; then 633252995Sdteske __n=$(( ${#__btitle} + 4 )) 634252995Sdteske [ $__n -gt $__width ] && __width=$__n 635252995Sdteske fi 636252995Sdteske 637252995Sdteske # 638252995Sdteske # Bump width for long prompts 639252995Sdteske # 640252995Sdteske __n=$( echo "$__prompt" | f_longest_line_length ) 641252995Sdteske __n=$(( $__n + 4 )) # add width for border 642252995Sdteske [ $__n -gt $__width ] && __width=$__n 643252995Sdteske 644252995Sdteske # 645252995Sdteske # Bump width for long hlines. Xdialog(1) supports `--hline' but 646252995Sdteske # it's currently not used (so don't do anything here if using 647252995Sdteske # Xdialog(1)). 648252995Sdteske # 649252995Sdteske if [ ! "$USE_XDIALOG" ]; then 650252995Sdteske __n=$(( ${#__hline} + 10 )) 651252995Sdteske [ $__n -gt $__width ] && __width=$__n 652252995Sdteske fi 653252995Sdteske 654252995Sdteske # Bump width by 16.6% if using Xdialog(1) 655252995Sdteske [ "$USE_XDIALOG" ] && __width=$(( $__width + $__width / 6 )) 656252995Sdteske 657252995Sdteske setvar "$__var_width" $__width 658252995Sdteske fi 659252995Sdteske 660252995Sdteske # Constrain values to sensible minimums/maximums unless `-n' was passed 661252995Sdteske # Return success if no-constrain, else return status from constrain 662252995Sdteske [ ! "$__constrain" ] || 663252995Sdteske f_dialog_size_constrain "$__var_height" "$__var_width" 664252995Sdteske} 665252995Sdteske 666252995Sdteske# f_dialog_buttonbox_size [-n] $var_height $var_width \ 667252995Sdteske# $title $backtitle $prompt [$hline] 668252995Sdteske# 669252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 670252995Sdteske# `--msgbox' and `--yesno' boxes sensibly. 671252995Sdteske# 672252995Sdteske# This function helps solve this issue by taking two sets of sequential 673252995Sdteske# arguments. The first set of arguments are the variable names to use when 674252995Sdteske# storing the calculated height and width. The second set of arguments are the 675252995Sdteske# title, backtitle, prompt, and [optionally] hline. The optimal height and 676252995Sdteske# width for the described widget (not exceeding the actual terminal height or 677252995Sdteske# width) is stored in $var_height and $var_width (respectively). 678252995Sdteske# 679252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height and 680252995Sdteske# $var_width) are not constrained to minimum/maximum values. 681252995Sdteske# 682252995Sdteske# Newline character sequences (``\n'') in $prompt are expanded as-is done by 683252995Sdteske# dialog(1). 684252995Sdteske# 685252995Sdteskef_dialog_buttonbox_size() 686252995Sdteske{ 687252995Sdteske local __constrain=1 688252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 689252995Sdteske local __var_height="$1" __var_width="$2" 690252995Sdteske local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" 691252995Sdteske 692252995Sdteske # Return unless at least one size aspect has been requested 693252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 694252995Sdteske 695252995Sdteske # Calculate height/width of infobox (adjusted/constrained below) 696252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 697252995Sdteske # from becoming local (and thus preventing setvar from working). 698252995Sdteske local __height_bbox_size __width_bbox_size 699252995Sdteske f_dialog_infobox_size -n \ 700252995Sdteske "${__var_height:+__height_bbox_size}" \ 701252995Sdteske "${__var_width:+__width_bbox_size}" \ 702252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 703252995Sdteske 704252995Sdteske # Adjust height if desired 705252995Sdteske if [ "$__var_height" ]; then 706252995Sdteske # Add height to accomodate the buttons 707252995Sdteske __height_bbox_size=$(( $__height_bbox_size + 2 )) 708252995Sdteske 709252995Sdteske # Adjust for clipping with Xdialog(1) on Linux/GTK2 710252995Sdteske [ "$USE_XDIALOG" ] && 711252995Sdteske __height_bbox_size=$(( $__height_bbox_size + 3 )) 712252995Sdteske 713252995Sdteske setvar "$__var_height" $__height_bbox_size 714252995Sdteske fi 715252995Sdteske 716252995Sdteske # No adjustemnts to width, just pass-thru the infobox width 717252995Sdteske if [ "$__var_width" ]; then 718252995Sdteske setvar "$__var_width" $__width_bbox_size 719252995Sdteske fi 720252995Sdteske 721252995Sdteske # Constrain values to sensible minimums/maximums unless `-n' was passed 722252995Sdteske # Return success if no-constrain, else return status from constrain 723252995Sdteske [ ! "$__constrain" ] || 724252995Sdteske f_dialog_size_constrain "$__var_height" "$__var_width" 725252995Sdteske} 726252995Sdteske 727252995Sdteske# f_dialog_inputbox_size [-n] $var_height $var_width \ 728252995Sdteske# $title $backtitle $prompt $init [$hline] 729252995Sdteske# 730252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 731252995Sdteske# `--inputbox' boxes sensibly. 732252995Sdteske# 733252995Sdteske# This function helps solve this issue by taking two sets of sequential 734252995Sdteske# arguments. The first set of arguments are the variable names to use when 735252995Sdteske# storing the calculated height and width. The second set of arguments are the 736252995Sdteske# title, backtitle, prompt, and [optionally] hline. The optimal height and 737252995Sdteske# width for the described widget (not exceeding the actual terminal height or 738252995Sdteske# width) is stored in $var_height and $var_width (respectively). 739252995Sdteske# 740252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height and 741252995Sdteske# $var_width) are not constrained to minimum/maximum values. 742252995Sdteske# 743252995Sdteske# Newline character sequences (``\n'') in $prompt are expanded as-is done by 744252995Sdteske# dialog(1). 745252995Sdteske# 746252995Sdteskef_dialog_inputbox_size() 747252995Sdteske{ 748252995Sdteske local __constrain=1 749252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 750252995Sdteske local __var_height="$1" __var_width="$2" 751252995Sdteske local __title="$3" __btitle="$4" __prompt="$5" __init="$6" __hline="$7" 752252995Sdteske 753252995Sdteske # Return unless at least one size aspect has been requested 754252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 755252995Sdteske 756252995Sdteske # Calculate height/width of buttonbox (adjusted/constrained below) 757252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 758252995Sdteske # from becoming local (and thus preventing setvar from working). 759252995Sdteske local __height_ibox_size __width_ibox_size 760252995Sdteske f_dialog_buttonbox_size -n \ 761252995Sdteske "${__var_height:+__height_ibox_size}" \ 762252995Sdteske "${__var_width:+__width_ibox_size}" \ 763252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 764252995Sdteske 765252995Sdteske # Adjust height if desired 766252995Sdteske if [ "$__var_height" ]; then 767252995Sdteske # Add height for input box (not needed for Xdialog(1)) 768252995Sdteske [ ! "$USE_XDIALOG" ] && 769252995Sdteske __height_ibox_size=$(( $__height_ibox_size + 3 )) 770252995Sdteske 771252995Sdteske setvar "$__var_height" $__height_ibox_size 772252995Sdteske fi 773252995Sdteske 774252995Sdteske # Adjust width if desired 775252995Sdteske if [ "$__var_width" ]; then 776252995Sdteske # Bump width for initial text (something neither dialog(1) nor 777252995Sdteske # Xdialog(1) do, but worth it!; add 16.6% if using Xdialog(1)) 778252995Sdteske local __n=$(( ${#__init} + 7 )) 779252995Sdteske [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) 780252995Sdteske [ $__n -gt $__width_ibox_size ] && __width_ibox_size=$__n 781252995Sdteske 782252995Sdteske setvar "$__var_width" $__width_ibox_size 783252995Sdteske fi 784252995Sdteske 785252995Sdteske # Constrain values to sensible minimums/maximums unless `-n' was passed 786252995Sdteske # Return success if no-constrain, else return status from constrain 787252995Sdteske [ ! "$__constrain" ] || 788252995Sdteske f_dialog_size_constrain "$__var_height" "$__var_width" 789252995Sdteske} 790252995Sdteske 791252995Sdteske# f_xdialog_2inputsbox_size [-n] $var_height $var_width \ 792252995Sdteske# $title $backtitle $prompt \ 793252995Sdteske# $label1 $init1 $label2 $init2 794252995Sdteske# 795252995Sdteske# Xdialog(1) does not perform auto-sizing of the width and height of 796252995Sdteske# `--2inputsbox' boxes sensibly. 797252995Sdteske# 798252995Sdteske# This function helps solve this issue by taking two sets of sequential 799252995Sdteske# arguments. The first set of arguments are the variable names to use when 800252995Sdteske# storing the calculated height and width. The second set of arguments are the 801252995Sdteske# title, backtitle, prompt, label for the first field, initial text for said 802252995Sdteske# field, label for the second field, and initial text for said field. The 803252995Sdteske# optimal height and width for the described widget (not exceeding the actual 804252995Sdteske# terminal height or width) is stored in $var_height and $var_width 805252995Sdteske# (respectively). 806252995Sdteske# 807252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height and 808252995Sdteske# $var_width) are not constrained to minimum/maximum values. 809252995Sdteske# 810252995Sdteske# Newline character sequences (``\n'') in $prompt are expanded as-is done by 811252995Sdteske# Xdialog(1). 812252995Sdteske# 813252995Sdteskef_xdialog_2inputsbox_size() 814252995Sdteske{ 815252995Sdteske local __constrain=1 816252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 817252995Sdteske local __var_height="$1" __var_width="$2" 818252995Sdteske local __title="$3" __btitle="$4" __prompt="$5" 819252995Sdteske local __label1="$6" __init1="$7" __label2="$8" __init2="$9" 820252995Sdteske 821252995Sdteske # Return unless at least one size aspect has been requested 822252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 823252995Sdteske 824252995Sdteske # Calculate height/width of inputbox (adjusted/constrained below) 825252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 826252995Sdteske # from becoming local (and thus preventing setvar from working). 827252995Sdteske local __height_2ibox_size __width_2ibox_size 828252995Sdteske f_dialog_inputbox_size -n \ 829252995Sdteske "${__var_height:+__height_2ibox_size}" \ 830252995Sdteske "${__var_width:+__width_2ibox_size}" \ 831252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" "$__init1" 832252995Sdteske 833252995Sdteske # Adjust height if desired 834252995Sdteske if [ "$__var_height" ]; then 835252995Sdteske # Add height for 1st label, 2nd label, and 2nd input box 836252995Sdteske __height_2ibox_size=$(( $__height_2ibox_size + 2 + 2 + 2 )) 837252995Sdteske setvar "$__var_height" $__height_2ibox_size 838252995Sdteske fi 839252995Sdteske 840252995Sdteske # Adjust width if desired 841252995Sdteske if [ "$__var_width" ]; then 842252995Sdteske local __n 843252995Sdteske 844252995Sdteske # Bump width for first label text (+16.6% since Xdialog(1)) 845252995Sdteske __n=$(( ${#__label1} + 7 )) 846252995Sdteske __n=$(( $__n + $__n / 6 )) 847252995Sdteske [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n 848252995Sdteske 849252995Sdteske # Bump width for second label text (+16.6% since Xdialog(1)) 850252995Sdteske __n=$(( ${#__label2} + 7 )) 851252995Sdteske __n=$(( $__n + $__n / 6 )) 852252995Sdteske [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n 853252995Sdteske 854252995Sdteske # Bump width for 2nd initial text (something neither dialog(1) 855252995Sdteske # nor Xdialog(1) do, but worth it!; +16.6% since Xdialog(1)) 856252995Sdteske __n=$(( ${#__init2} + 7 )) 857252995Sdteske __n=$(( $__n + $__n / 6 )) 858252995Sdteske [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n 859252995Sdteske 860252995Sdteske setvar "$__var_width" $__width_2ibox_size 861252995Sdteske fi 862252995Sdteske 863252995Sdteske # Constrain values to sensible minimums/maximums unless `-n' was passed 864252995Sdteske # Return success if no-constrain, else return status from constrain 865252995Sdteske [ ! "$__constrain" ] || 866252995Sdteske f_dialog_size_constrain "$__var_height" "$__var_width" 867252995Sdteske} 868252995Sdteske 869252995Sdteske# f_dialog_menu_size [-n] $var_height $var_width $var_rows \ 870252995Sdteske# $title $backtitle $prompt $hline \ 871252995Sdteske# $tag1 $item1 $tag2 $item2 ... 872252995Sdteske# 873252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 874252995Sdteske# `--menu' boxes sensibly. 875252995Sdteske# 876252995Sdteske# This function helps solve this issue by taking three sets of sequential 877252995Sdteske# arguments. The first set of arguments are the variable names to use when 878252995Sdteske# storing the calculated height, width, and rows. The second set of arguments 879252995Sdteske# are the title, backtitle, prompt, and hline. The [optional] third set of 880252995Sdteske# arguments are the menu list itself (comprised of tag/item couplets). The 881252995Sdteske# optimal height, width, and rows for the described widget (not exceeding the 882252995Sdteske# actual terminal height or width) is stored in $var_height, $var_width, and 883252995Sdteske# $var_rows (respectively). 884252995Sdteske# 885252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height, $var_width, 886252995Sdteske# and $var_rows) are not constrained to minimum/maximum values. 887252995Sdteske# 888252995Sdteskef_dialog_menu_size() 889252995Sdteske{ 890252995Sdteske local __constrain=1 891252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 892252995Sdteske local __var_height="$1" __var_width="$2" __var_rows="$3" 893252995Sdteske local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" 894252995Sdteske shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline 895252995Sdteske 896252995Sdteske # Return unless at least one size aspect has been requested 897252995Sdteske [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || 898252995Sdteske return $FAILURE 899252995Sdteske 900252995Sdteske # Calculate height/width of infobox (adjusted/constrained below) 901252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 902252995Sdteske # from becoming local (and thus preventing setvar from working). 903252995Sdteske local __height_menu_size __width_menu_size 904252995Sdteske f_dialog_infobox_size -n \ 905252995Sdteske "${__var_height:+__height_menu_size}" \ 906252995Sdteske "${__var_width:+__width_menu_size}" \ 907252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 908252995Sdteske 909252995Sdteske # 910252995Sdteske # Always process the menu-item arguments to get the longest tag-length, 911252995Sdteske # longest item-length (both used to bump the width), and the number of 912252995Sdteske # rows (used to bump the height). 913252995Sdteske # 914252995Sdteske local __longest_tag=0 __longest_item=0 __rows=0 915252995Sdteske while [ $# -ge 2 ]; do 916252995Sdteske local __tag="$1" __item="$2" 917252995Sdteske shift 2 # tag/item 918252995Sdteske [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} 919252995Sdteske [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} 920252995Sdteske __rows=$(( $__rows + 1 )) 921252995Sdteske done 922252995Sdteske 923252995Sdteske # Adjust rows early (for up-comning height calculation) 924252995Sdteske if [ "$__var_height" -o "$__var_rows" ]; then 925252995Sdteske # Add a row for visual aid if using Xdialog(1) 926252995Sdteske [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) 927252995Sdteske fi 928252995Sdteske 929252995Sdteske # Adjust height if desired 930252995Sdteske if [ "$__var_height" ]; then 931252995Sdteske # Add rows to height 932252995Sdteske if [ "$USE_XDIALOG" ]; then 933252995Sdteske __height_menu_size=$(( 934252995Sdteske $__height_menu_size + $__rows + 7 )) 935252995Sdteske else 936252995Sdteske __height_menu_size=$(( 937252995Sdteske $__height_menu_size + $__rows + 4 )) 938252995Sdteske fi 939252995Sdteske setvar "$__var_height" $__height_menu_size 940252995Sdteske fi 941252995Sdteske 942252995Sdteske # Adjust width if desired 943252995Sdteske if [ "$__var_width" ]; then 944252995Sdteske # The sum total between the longest tag-length and the 945252995Sdteske # longest item-length should be used to bump menu width 946252995Sdteske local __n=$(( $__longest_tag + $__longest_item + 10 )) 947252995Sdteske [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% 948252995Sdteske [ $__n -gt $__width_menu_size ] && __width_menu_size=$__n 949252995Sdteske 950252995Sdteske setvar "$__var_width" $__width_menu_size 951252995Sdteske fi 952252995Sdteske 953252995Sdteske # Store adjusted rows if desired 954252995Sdteske [ "$__var_rows" ] && setvar "$__var_rows" $__rows 955252995Sdteske 956252995Sdteske # Constrain height, width, and rows to sensible minimum/maximum values 957252995Sdteske # Return success if no-constrain, else return status from constrain 958252995Sdteske [ ! "$__constrain" ] || f_dialog_menu_constrain \ 959252995Sdteske "$__var_height" "$__var_width" "$__var_rows" "$__prompt" 960252995Sdteske} 961252995Sdteske 962252995Sdteske# f_dialog_menu_with_help_size [-n] $var_height $var_width $var_rows \ 963252995Sdteske# $title $backtitle $prompt $hline \ 964252995Sdteske# $tag1 $item1 $help1 $tag2 $item2 $help2 ... 965252995Sdteske# 966252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 967252995Sdteske# `--menu' boxes sensibly. 968252995Sdteske# 969252995Sdteske# This function helps solve this issue by taking three sets of sequential 970252995Sdteske# arguments. The first set of arguments are the variable names to use when 971252995Sdteske# storing the calculated height, width, and rows. The second set of arguments 972252995Sdteske# are the title, backtitle, prompt, and hline. The [optional] third set of 973252995Sdteske# arguments are the menu list itself (comprised of tag/item/help triplets). The 974252995Sdteske# optimal height, width, and rows for the described widget (not exceeding the 975252995Sdteske# actual terminal height or width) is stored in $var_height, $var_width, and 976252995Sdteske# $var_rows (respectively). 977252995Sdteske# 978252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height, $var_width, 979252995Sdteske# and $var_rows) are not constrained to minimum/maximum values. 980252995Sdteske# 981252995Sdteskef_dialog_menu_with_help_size() 982252995Sdteske{ 983252995Sdteske local __constrain=1 984252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 985252995Sdteske local __var_height="$1" __var_width="$2" __var_rows="$3" 986252995Sdteske local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" 987252995Sdteske shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline 988252995Sdteske 989252995Sdteske # Return unless at least one size aspect has been requested 990252995Sdteske [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || 991252995Sdteske return $FAILURE 992252995Sdteske 993252995Sdteske # Calculate height/width of infobox (adjusted/constrained below) 994252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 995252995Sdteske # from becoming local (and thus preventing setvar from working). 996252995Sdteske local __height_menu_with_help_size __width_menu_with_help_size 997252995Sdteske f_dialog_infobox_size -n \ 998252995Sdteske "${__var_height:+__height_menu_with_help_size}" \ 999252995Sdteske "${__var_width:+__width_menu_with_help_size}" \ 1000252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 1001252995Sdteske 1002252995Sdteske # 1003252995Sdteske # Always process the menu-item arguments to get the longest tag-length, 1004252995Sdteske # longest item-length, longest help-length (help-length only considered 1005252995Sdteske # if using Xdialog(1), as it places the help string in the widget) -- 1006252995Sdteske # all used to bump the width -- and the number of rows (used to bump 1007252995Sdteske # the height). 1008252995Sdteske # 1009252995Sdteske local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0 1010252995Sdteske while [ $# -ge 3 ]; do 1011252995Sdteske local __tag="$1" __item="$2" __help="$3" 1012252995Sdteske shift 3 # tag/item/help 1013252995Sdteske [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} 1014252995Sdteske [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} 1015252995Sdteske [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help} 1016252995Sdteske __rows=$(( $__rows + 1 )) 1017252995Sdteske done 1018252995Sdteske 1019252995Sdteske # Adjust rows early (for up-coming height calculation) 1020252995Sdteske if [ "$__var_height" -o "$__var_rows" ]; then 1021252995Sdteske # Add a row for visual aid if using Xdialog(1) 1022252995Sdteske [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 )) 1023252995Sdteske fi 1024252995Sdteske 1025252995Sdteske # Adjust height if desired 1026252995Sdteske if [ "$__var_height" ]; then 1027252995Sdteske # Add rows to height 1028252995Sdteske if [ "$USE_XDIALOG" ]; then 1029252995Sdteske __height_menu_with_help_size=$(( 1030252995Sdteske $__height_menu_with_help_size + $__rows + 8 )) 1031252995Sdteske else 1032252995Sdteske __height_menu_with_help_size=$(( 1033252995Sdteske $__height_menu_with_help_size + $__rows + 4 )) 1034252995Sdteske fi 1035252995Sdteske setvar "$__var_height" $__height_menu_with_help_size 1036252995Sdteske fi 1037252995Sdteske 1038252995Sdteske # Adjust width if desired 1039252995Sdteske if [ "$__var_width" ]; then 1040252995Sdteske # The sum total between the longest tag-length and the 1041252995Sdteske # longest item-length should be used to bump menu width 1042252995Sdteske local __n=$(( $__longest_tag + $__longest_item + 10 )) 1043252995Sdteske [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% 1044252995Sdteske [ $__n -gt $__width_menu_with_help_size ] && 1045252995Sdteske __width_menu_with_help_size=$__n 1046252995Sdteske 1047252995Sdteske # Update width for help text if using Xdialog(1) 1048252995Sdteske if [ "$USE_XDIALOG" ]; then 1049252995Sdteske __n=$(( $__longest_help + 10 )) 1050252995Sdteske __n=$(( $__n + $__n / 6 )) # plus 16.6% 1051252995Sdteske [ $__n -gt $__width_menu_with_help_size ] && 1052252995Sdteske __width_menu_with_help_size=$__n 1053252995Sdteske fi 1054252995Sdteske 1055252995Sdteske setvar "$__var_width" $__width_menu_with_help_size 1056252995Sdteske fi 1057252995Sdteske 1058252995Sdteske # Store adjusted rows if desired 1059252995Sdteske [ "$__var_rows" ] && setvar "$__var_rows" $__rows 1060252995Sdteske 1061252995Sdteske # Constrain height, width, and rows to sensible minimum/maximum values 1062252995Sdteske # Return success if no-constrain, else return status from constrain 1063252995Sdteske [ ! "$__constrain" ] || f_dialog_menu_constrain \ 1064252995Sdteske "$__var_height" "$__var_width" "$__var_rows" "$__prompt" 1065252995Sdteske} 1066252995Sdteske 1067252995Sdteske# f_dialog_radiolist_size [-n] $var_height $var_width $var_rows \ 1068252995Sdteske# $title $backtitle $prompt $hline \ 1069252995Sdteske# $tag1 $item1 $status1 $tag2 $item2 $status2 ... 1070252995Sdteske# 1071252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 1072252995Sdteske# `--radiolist' boxes sensibly. 1073252995Sdteske# 1074252995Sdteske# This function helps solve this issue by taking three sets of sequential 1075252995Sdteske# arguments. The first set of arguments are the variable names to use when 1076252995Sdteske# storing the calculated height, width, and rows. The second set of arguments 1077252995Sdteske# are the title, backtitle, prompt, and hline. The [optional] third set of 1078252995Sdteske# arguments are the radio list itself (comprised of tag/item/status triplets). 1079252995Sdteske# The optimal height, width, and rows for the described widget (not exceeding 1080252995Sdteske# the actual terminal height or width) is stored in $var_height, $var_width, 1081252995Sdteske# and $var_rows (respectively). 1082252995Sdteske# 1083252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height, $var_width, 1084252995Sdteske# and $var_rows) are not constrained to minimum/maximum values. 1085252995Sdteske# 1086252995Sdteskef_dialog_radiolist_size() 1087252995Sdteske{ 1088252995Sdteske local __constrain=1 1089252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 1090252995Sdteske local __var_height="$1" __var_width="$2" __var_rows="$3" 1091252995Sdteske local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" 1092252995Sdteske shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline 1093252995Sdteske 1094252995Sdteske # Return unless at least one size aspect has been requested 1095252995Sdteske [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || 1096252995Sdteske return $FAILURE 1097252995Sdteske 1098252995Sdteske # Calculate height/width of infobox (adjusted/constrained below) 1099252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 1100252995Sdteske # from becoming local (and thus preventing setvar from working). 1101252995Sdteske local __height_rlist_size __width_rlist_size 1102252995Sdteske f_dialog_infobox_size -n \ 1103252995Sdteske "${__var_height:+__height_rlist_size}" \ 1104252995Sdteske "${__var_width:+__width_rlist_size}" \ 1105252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 1106252995Sdteske 1107252995Sdteske # 1108252995Sdteske # Always process the menu-item arguments to get the longest tag-length, 1109252995Sdteske # longest item-length (both used to bump the width), and the number of 1110252995Sdteske # rows (used to bump the height). 1111252995Sdteske # 1112263791Sdteske local __longest_tag=0 __longest_item=0 __rows_rlist_size=0 1113252995Sdteske while [ $# -ge 3 ]; do 1114252995Sdteske local __tag="$1" __item="$2" 1115252995Sdteske shift 3 # tag/item/status 1116252995Sdteske [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} 1117252995Sdteske [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} 1118263791Sdteske __rows_rlist_size=$(( $__rows_rlist_size + 1 )) 1119252995Sdteske done 1120252995Sdteske 1121252995Sdteske # Adjust rows early (for up-coming height calculation) 1122252995Sdteske if [ "$__var_height" -o "$__var_rows" ]; then 1123252995Sdteske # Add a row for visual aid if using Xdialog(1) 1124263791Sdteske [ "$USE_XDIALOG" ] && 1125263791Sdteske __rows_rlist_size=$(( $__rows_rlist_size + 1 )) 1126252995Sdteske fi 1127252995Sdteske 1128252995Sdteske # Adjust height if desired 1129252995Sdteske if [ "$__var_height" ]; then 1130252995Sdteske # Add rows to height 1131252995Sdteske if [ "$USE_XDIALOG" ]; then 1132252995Sdteske __height_rlist_size=$(( 1133263791Sdteske $__height_rlist_size + $__rows_rlist_size + 7 1134263791Sdteske )) 1135252995Sdteske else 1136252995Sdteske __height_rlist_size=$(( 1137263791Sdteske $__height_rlist_size + $__rows_rlist_size + 4 1138263791Sdteske )) 1139252995Sdteske fi 1140252995Sdteske setvar "$__var_height" $__height_rlist_size 1141252995Sdteske fi 1142252995Sdteske 1143252995Sdteske # Adjust width if desired 1144252995Sdteske if [ "$__var_width" ]; then 1145252995Sdteske # Sum total between longest tag-length, longest item-length, 1146252995Sdteske # and radio-button width should be used to bump menu width 1147252995Sdteske local __n=$(( $__longest_tag + $__longest_item + 13 )) 1148252995Sdteske [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% 1149252995Sdteske [ $__n -gt $__width_rlist_size ] && __width_rlist_size=$__n 1150252995Sdteske 1151252995Sdteske setvar "$__var_width" $__width_rlist_size 1152252995Sdteske fi 1153252995Sdteske 1154252995Sdteske # Store adjusted rows if desired 1155263791Sdteske [ "$__var_rows" ] && setvar "$__var_rows" $__rows_rlist_size 1156252995Sdteske 1157252995Sdteske # Constrain height, width, and rows to sensible minimum/maximum values 1158252995Sdteske # Return success if no-constrain, else return status from constrain 1159252995Sdteske [ ! "$__constrain" ] || f_dialog_menu_constrain \ 1160252995Sdteske "$__var_height" "$__var_width" "$__var_rows" "$__prompt" 1161252995Sdteske} 1162252995Sdteske 1163252995Sdteske# f_dialog_checklist_size [-n] $var_height $var_width $var_rows \ 1164252995Sdteske# $title $backtitle $prompt $hline \ 1165252995Sdteske# $tag1 $item1 $status1 $tag2 $item2 $status2 ... 1166252995Sdteske# 1167252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 1168252995Sdteske# `--checklist' boxes sensibly. 1169252995Sdteske# 1170252995Sdteske# This function helps solve this issue by taking three sets of sequential 1171252995Sdteske# arguments. The first set of arguments are the variable names to use when 1172252995Sdteske# storing the calculated height, width, and rows. The second set of arguments 1173252995Sdteske# are the title, backtitle, prompt, and hline. The [optional] third set of 1174252995Sdteske# arguments are the check list itself (comprised of tag/item/status triplets). 1175252995Sdteske# The optimal height, width, and rows for the described widget (not exceeding 1176252995Sdteske# the actual terminal height or width) is stored in $var_height, $var_width, 1177252995Sdteske# and $var_rows (respectively). 1178252995Sdteske# 1179252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height, $var_width, 1180252995Sdteske# and $var_rows) are not constrained to minimum/maximum values. 1181252995Sdteske# 1182252995Sdteskef_dialog_checklist_size() 1183252995Sdteske{ 1184252995Sdteske f_dialog_radiolist_size "$@" 1185252995Sdteske} 1186252995Sdteske 1187252995Sdteske# f_dialog_radiolist_with_help_size [-n] $var_height $var_width $var_rows \ 1188252995Sdteske# $title $backtitle $prompt $hline \ 1189252995Sdteske# $tag1 $item1 $status1 $help1 \ 1190252995Sdteske# $tag2 $item2 $status2 $help2 ... 1191252995Sdteske# 1192252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 1193252995Sdteske# `--radiolist' boxes sensibly. 1194252995Sdteske# 1195252995Sdteske# This function helps solve this issue by taking three sets of sequential 1196252995Sdteske# arguments. The first set of arguments are the variable names to use when 1197252995Sdteske# storing the calculated height, width, and rows. The second set of arguments 1198252995Sdteske# are the title, backtitle, prompt, and hline. The [optional] third set of 1199252995Sdteske# arguments are the radio list itself (comprised of tag/item/status/help 1200252995Sdteske# quadruplets). The optimal height, width, and rows for the described widget 1201252995Sdteske# (not exceeding the actual terminal height or width) is stored in $var_height, 1202252995Sdteske# $var_width, and $var_rows (respectively). 1203252995Sdteske# 1204252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height, $var_width, 1205252995Sdteske# and $var_rows) are not constrained to minimum/maximum values. 1206252995Sdteske# 1207252995Sdteskef_dialog_radiolist_with_help_size() 1208252995Sdteske{ 1209252995Sdteske local __constrain=1 1210252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 1211252995Sdteske local __var_height="$1" __var_width="$2" __var_rows="$3" 1212252995Sdteske local __title="$4" __btitle="$5" __prompt="$6" __hline="$7" 1213252995Sdteske shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline 1214252995Sdteske 1215252995Sdteske # Return unless at least one size aspect has been requested 1216252995Sdteske [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] || 1217252995Sdteske return $FAILURE 1218252995Sdteske 1219252995Sdteske # Calculate height/width of infobox (adjusted/constrained below) 1220252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 1221252995Sdteske # from becoming local (and thus preventing setvar from working). 1222252995Sdteske local __height_rlist_with_help_size __width_rlist_with_help_size 1223252995Sdteske f_dialog_infobox_size -n \ 1224252995Sdteske "${__var_height:+__height_rlist_with_help_size}" \ 1225252995Sdteske "${__var_width:+__width_rlist_with_help_size}" \ 1226252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 1227252995Sdteske 1228252995Sdteske # 1229252995Sdteske # Always process the menu-item arguments to get the longest tag-length, 1230252995Sdteske # longest item-length, longest help-length (help-length only considered 1231252995Sdteske # if using Xdialog(1), as it places the help string in the widget) -- 1232252995Sdteske # all used to bump the width -- and the number of rows (used to bump 1233252995Sdteske # the height). 1234252995Sdteske # 1235263791Sdteske local __longest_tag=0 __longest_item=0 __longest_help=0 1236263791Sdteske local __rows_rlist_with_help_size=0 1237252995Sdteske while [ $# -ge 4 ]; do 1238252995Sdteske local __tag="$1" __item="$2" __status="$3" __help="$4" 1239252995Sdteske shift 4 # tag/item/status/help 1240252995Sdteske [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag} 1241252995Sdteske [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item} 1242252995Sdteske [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help} 1243263791Sdteske __rows_rlist_with_help_size=$(( 1244263791Sdteske $__rows_rlist_with_help_size + 1 1245263791Sdteske )) 1246252995Sdteske done 1247252995Sdteske 1248252995Sdteske # Adjust rows early (for up-coming height calculation) 1249252995Sdteske if [ "$__var_height" -o "$__var_rows" ]; then 1250252995Sdteske # Add a row for visual aid if using Xdialog(1) 1251263791Sdteske [ "$USE_XDIALOG" ] && 1252263791Sdteske __rows_rlist_with_help_size=$(( 1253263791Sdteske $__rows_rlist_with_help_size + 1 1254263791Sdteske )) 1255252995Sdteske fi 1256252995Sdteske 1257252995Sdteske # Adjust height if desired 1258252995Sdteske if [ "$__var_height" ]; then 1259252995Sdteske # Add rows to height 1260252995Sdteske if [ "$USE_XDIALOG" ]; then 1261252995Sdteske __height_rlist_with_help_size=$(( 1262263791Sdteske $__height_rlist_with_help_size + 1263263791Sdteske $__rows_rlist_with_help_size + 7 1264263791Sdteske )) 1265252995Sdteske else 1266252995Sdteske __height_rlist_with_help_size=$(( 1267263791Sdteske $__height_rlist_with_help_size + 1268263791Sdteske $__rows_rlist_with_help_size + 4 1269263791Sdteske )) 1270252995Sdteske fi 1271252995Sdteske setvar "$__var_height" $__height 1272252995Sdteske fi 1273252995Sdteske 1274252995Sdteske # Adjust width if desired 1275252995Sdteske if [ "$__var_width" ]; then 1276252995Sdteske # Sum total between longest tag-length, longest item-length, 1277252995Sdteske # and radio-button width should be used to bump menu width 1278252995Sdteske local __n=$(( $__longest_tag + $__longest_item + 13 )) 1279252995Sdteske [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6% 1280252995Sdteske [ $__n -gt $__width_rlist_with_help_size ] && 1281252995Sdteske __width_rlist_with_help_size=$__n 1282252995Sdteske 1283252995Sdteske # Update width for help text if using Xdialog(1) 1284252995Sdteske if [ "$USE_XDIALOG" ]; then 1285252995Sdteske __n=$(( $__longest_help + 10 )) 1286252995Sdteske __n=$(( $__n + $__n / 6 )) # plus 16.6% 1287252995Sdteske [ $__n -gt $__width_rlist_with_help_size ] && 1288252995Sdteske __width_rlist_with_help_size=$__n 1289252995Sdteske fi 1290252995Sdteske 1291252995Sdteske setvar "$__var_width" $__width_rlist_with_help_size 1292252995Sdteske fi 1293252995Sdteske 1294252995Sdteske # Store adjusted rows if desired 1295263791Sdteske [ "$__var_rows" ] && setvar "$__var_rows" $__rows_rlist_with_help_size 1296252995Sdteske 1297252995Sdteske # Constrain height, width, and rows to sensible minimum/maximum values 1298252995Sdteske # Return success if no-constrain, else return status from constrain 1299252995Sdteske [ ! "$__constrain" ] || f_dialog_menu_constrain \ 1300252995Sdteske "$__var_height" "$__var_width" "$__var_rows" "$__prompt" 1301252995Sdteske} 1302252995Sdteske 1303252995Sdteske# f_dialog_checklist_with_help_size [-n] $var_height $var_width $var_rows \ 1304252995Sdteske# $title $backtitle $prompt $hline \ 1305252995Sdteske# $tag1 $item1 $status1 $help1 \ 1306252995Sdteske# $tag2 $item2 $status2 $help2 ... 1307252995Sdteske# 1308252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 1309252995Sdteske# `--checklist' boxes sensibly. 1310252995Sdteske# 1311252995Sdteske# This function helps solve this issue by taking three sets of sequential 1312252995Sdteske# arguments. The first set of arguments are the variable names to use when 1313252995Sdteske# storing the calculated height, width, and rows. The second set of arguments 1314252995Sdteske# are the title, backtitle, prompt, and hline. The [optional] third set of 1315252995Sdteske# arguments are the check list itself (comprised of tag/item/status/help 1316252995Sdteske# quadruplets). The optimal height, width, and rows for the described widget 1317252995Sdteske# (not exceeding the actual terminal height or width) is stored in $var_height, 1318252995Sdteske# $var_width, and $var_rows (respectively). 1319252995Sdteske# 1320252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height, $var_width, 1321252995Sdteske# and $var_rows) are not constrained to minimum/maximum values. 1322252995Sdteske# 1323252995Sdteskef_dialog_checklist_with_help_size() 1324252995Sdteske{ 1325252995Sdteske f_dialog_radiolist_with_help_size "$@" 1326252995Sdteske} 1327252995Sdteske 1328252995Sdteske# f_dialog_calendar_size [-n] $var_height $var_width \ 1329252995Sdteske# $title $backtitle $prompt [$hline] 1330252995Sdteske# 1331252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 1332252995Sdteske# `--calendar' boxes sensibly. 1333252995Sdteske# 1334252995Sdteske# This function helps solve this issue by taking two sets of sequential 1335252995Sdteske# arguments. The first set of arguments are the variable names to use when 1336252995Sdteske# storing the calculated height and width. The second set of arguments are the 1337252995Sdteske# title, backtitle, prompt, and [optionally] hline. The optimal height and 1338252995Sdteske# width for the described widget (not exceeding the actual terminal height or 1339252995Sdteske# width) is stored in $var_height and $var_width (respectively). 1340252995Sdteske# 1341252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height and 1342252995Sdteske# $var_width) are not constrained to minimum/maximum values. 1343252995Sdteske# 1344252995Sdteske# Newline character sequences (``\n'') in $prompt are expanded as-is done by 1345252995Sdteske# dialog(1). 1346252995Sdteske# 1347252995Sdteskef_dialog_calendar_size() 1348252995Sdteske{ 1349252995Sdteske local __constrain=1 1350252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 1351252995Sdteske local __var_height="$1" __var_width="$2" 1352252995Sdteske local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" 1353252995Sdteske 1354252995Sdteske # Return unless at least one size aspect has been requested 1355252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 1356252995Sdteske 1357252995Sdteske # 1358252995Sdteske # Obtain/Adjust minimum and maximum thresholds 1359252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 1360252995Sdteske # from becoming local (and thus preventing setvar from working). 1361252995Sdteske # 1362252995Sdteske local __max_height_cal_size __max_width_cal_size 1363252995Sdteske f_dialog_max_size __max_height_cal_size __max_width_cal_size 1364252995Sdteske __max_width_cal_size=$(( $__max_width_cal_size - 2 )) 1365252995Sdteske # the calendar box will refuse to display if too wide 1366252995Sdteske local __min_width 1367252995Sdteske if [ "$USE_XDIALOG" ]; then 1368252995Sdteske __min_width=55 1369252995Sdteske else 1370252995Sdteske __min_width=40 1371252995Sdteske __max_height_cal_size=$(( 1372252995Sdteske $__max_height_cal_size - $DIALOG_CALENDAR_HEIGHT )) 1373252995Sdteske # When using dialog(1), we can't predict whether the user has 1374252995Sdteske # disabled shadow's in their `$HOME/.dialogrc' file, so we'll 1375252995Sdteske # subtract one for the potential shadow around the widget 1376252995Sdteske __max_height_cal_size=$(( $__max_height_cal_size - 1 )) 1377252995Sdteske fi 1378252995Sdteske 1379252995Sdteske # Calculate height if desired 1380252995Sdteske if [ "$__var_height" ]; then 1381252995Sdteske local __height 1382252995Sdteske __height=$( echo "$__prompt" | f_number_of_lines ) 1383252995Sdteske 1384252995Sdteske if [ "$USE_XDIALOG" ]; then 1385252995Sdteske # Add height to accomodate for embedded calendar widget 1386252995Sdteske __height=$(( $__height + $DIALOG_CALENDAR_HEIGHT - 1 )) 1387252995Sdteske 1388252995Sdteske # Also, bump height if backtitle is enabled 1389252995Sdteske if [ "$__btitle" ]; then 1390252995Sdteske local __n 1391252995Sdteske __n=$( echo "$__btitle" | f_number_of_lines ) 1392252995Sdteske __height=$(( $__height + $__n + 2 )) 1393252995Sdteske fi 1394252995Sdteske else 1395252995Sdteske [ "$__prompt" ] && __height=$(( $__height + 1 )) 1396252995Sdteske fi 1397252995Sdteske 1398252995Sdteske # Enforce maximum height, unless `-n' was passed 1399252995Sdteske [ "$__constrain" -a $__height -gt $__max_height_cal_size ] && 1400252995Sdteske __height=$__max_height_cal_size 1401252995Sdteske 1402252995Sdteske setvar "$__var_height" $__height 1403252995Sdteske fi 1404252995Sdteske 1405252995Sdteske # Calculate width if desired 1406252995Sdteske if [ "$__var_width" ]; then 1407252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} 1408252995Sdteske # values from becoming local (and thus preventing setvar 1409252995Sdteske # from working). 1410252995Sdteske local __width_cal_size 1411252995Sdteske f_dialog_infobox_size -n "" __width_cal_size \ 1412252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 1413252995Sdteske 1414252995Sdteske # Enforce minimum/maximum width, unless `-n' was passed 1415252995Sdteske if [ "$__constrain" ]; then 1416252995Sdteske if [ $__width_cal_size -lt $__min_width ]; then 1417252995Sdteske __width_cal_size=$__min_width 1418252995Sdteske elif [ $__width_cal_size -gt $__max_width_cal_size ] 1419252995Sdteske then 1420252995Sdteske __width_cal_size=$__max_width_size 1421252995Sdteske fi 1422252995Sdteske fi 1423252995Sdteske 1424252995Sdteske setvar "$__var_width" $__width_cal_size 1425252995Sdteske fi 1426252995Sdteske 1427252995Sdteske return $SUCCESS 1428252995Sdteske} 1429252995Sdteske 1430252995Sdteske# f_dialog_timebox_size [-n] $var_height $var_width \ 1431252995Sdteske# $title $backtitle $prompt [$hline] 1432252995Sdteske# 1433252995Sdteske# Not all versions of dialog(1) perform auto-sizing of the width and height of 1434252995Sdteske# `--timebox' boxes sensibly. 1435252995Sdteske# 1436252995Sdteske# This function helps solve this issue by taking two sets of sequential 1437252995Sdteske# arguments. The first set of arguments are the variable names to use when 1438252995Sdteske# storing the calculated height and width. The second set of arguments are the 1439252995Sdteske# title, backtitle, prompt, and [optionally] hline. The optional height and 1440252995Sdteske# width for the described widget (not exceeding the actual terminal height or 1441252995Sdteske# width) is stored in $var_height and $var_width (respectively). 1442252995Sdteske# 1443252995Sdteske# If the first argument is `-n', the calculated sizes ($var_height and 1444252995Sdteske# $var_width) are not constrained to minimum/maximum values. 1445252995Sdteske# 1446252995Sdteske# Newline character sequences (``\n'') in $prompt are expanded as-is done by 1447252995Sdteske# dialog(1). 1448252995Sdteske# 1449252995Sdteskef_dialog_timebox_size() 1450252995Sdteske{ 1451252995Sdteske local __constrain=1 1452252995Sdteske [ "$1" = "-n" ] && __constrain= && shift 1 # -n 1453252995Sdteske local __var_height="$1" __var_width="$2" 1454252995Sdteske local __title="$3" __btitle="$4" __prompt="$5" __hline="$6" 1455252995Sdteske 1456252995Sdteske # Return unless at least one size aspect has been requested 1457252995Sdteske [ "$__var_height" -o "$__var_width" ] || return $FAILURE 1458252995Sdteske 1459252995Sdteske # 1460252995Sdteske # Obtain/Adjust minimum and maximum thresholds 1461252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 1462252995Sdteske # from becoming local (and thus preventing setvar from working). 1463252995Sdteske # 1464252995Sdteske local __max_height_tbox_size __max_width_tbox_size 1465252995Sdteske f_dialog_max_size __max_height_tbox_size __max_width_tbox_size 1466252995Sdteske __max_width_tbox_size=$(( $__max_width_tbox_size - 2 )) 1467252995Sdteske # the timebox widget refuses to display if too wide 1468252995Sdteske local __min_width 1469252995Sdteske if [ "$USE_XDIALOG" ]; then 1470252995Sdteske __min_width=40 1471252995Sdteske else 1472252995Sdteske __min_width=20 1473252995Sdteske __max_height_tbox_size=$(( \ 1474252995Sdteske $__max_height_tbox_size - $DIALOG_TIMEBOX_HEIGHT )) 1475252995Sdteske # When using dialog(1), we can't predict whether the user has 1476252995Sdteske # disabled shadow's in their `$HOME/.dialogrc' file, so we'll 1477252995Sdteske # subtract one for the potential shadow around the widget 1478252995Sdteske __max_height_tbox_size=$(( $__max_height_tbox_size - 1 )) 1479252995Sdteske fi 1480252995Sdteske 1481252995Sdteske # Calculate height if desired 1482252995Sdteske if [ "$__var_height" -a "$USE_XDIALOG" ]; then 1483252995Sdteske # When using Xdialog(1), the height seems to have 1484252995Sdteske # no effect. All values provide the same results. 1485252995Sdteske setvar "$__var_height" 0 # autosize 1486252995Sdteske elif [ "$__var_height" ]; then 1487252995Sdteske local __height 1488252995Sdteske __height=$( echo "$__prompt" | f_number_of_lines ) 1489252995Sdteske __height=$(( $__height ${__prompt:++1} + 1 )) 1490252995Sdteske 1491252995Sdteske # Enforce maximum height, unless `-n' was passed 1492252995Sdteske [ "$__constrain" -a $__height -gt $__max_height_tbox_size ] && 1493252995Sdteske __height=$__max_height_tbox_size 1494252995Sdteske 1495252995Sdteske setvar "$__var_height" $__height 1496252995Sdteske fi 1497252995Sdteske 1498252995Sdteske # Calculate width if desired 1499252995Sdteske if [ "$__var_width" ]; then 1500252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} 1501252995Sdteske # values from becoming local (and thus preventing setvar 1502252995Sdteske # from working). 1503252995Sdteske local __width_tbox_size 1504252995Sdteske f_dialog_infobox_size -n "" __width_tbox_size \ 1505252995Sdteske "$__title" "$__btitle" "$__prompt" "$__hline" 1506252995Sdteske 1507252995Sdteske # Enforce the minimum width for displaying the timebox 1508252995Sdteske if [ "$__constrain" ]; then 1509252995Sdteske if [ $__width_tbox_size -lt $__min_width ]; then 1510252995Sdteske __width_tbox_size=$__min_width 1511252995Sdteske elif [ $__width_tbox_size -ge $__max_width_tbox_size ] 1512252995Sdteske then 1513252995Sdteske __width_tbox_size=$__max_width_tbox_size 1514252995Sdteske fi 1515252995Sdteske fi 1516252995Sdteske 1517252995Sdteske setvar "$__var_width" $__width_tbox_size 1518252995Sdteske fi 1519252995Sdteske 1520252995Sdteske return $SUCCESS 1521252995Sdteske} 1522252995Sdteske 1523252995Sdteske############################################################ CLEAR FUNCTIONS 1524252995Sdteske 1525252995Sdteske# f_dialog_clear 1526252995Sdteske# 1527252995Sdteske# Clears any/all previous dialog(1) displays. 1528252995Sdteske# 1529252995Sdteskef_dialog_clear() 1530252995Sdteske{ 1531252995Sdteske $DIALOG --clear 1532252995Sdteske} 1533252995Sdteske 1534252995Sdteske############################################################ INFO FUNCTIONS 1535252995Sdteske 1536252995Sdteske# f_dialog_info $info_text ... 1537252995Sdteske# 1538252995Sdteske# Throw up a dialog(1) infobox. The infobox remains until another dialog is 1539252995Sdteske# displayed or `dialog --clear' (or f_dialog_clear) is called. 1540252995Sdteske# 1541252995Sdteskef_dialog_info() 1542252995Sdteske{ 1543252995Sdteske local info_text="$*" height width 1544252995Sdteske f_dialog_infobox_size height width \ 1545252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text" 1546252995Sdteske $DIALOG \ 1547252995Sdteske --title "$DIALOG_TITLE" \ 1548252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1549252995Sdteske ${USE_XDIALOG:+--ignore-eof} \ 1550252995Sdteske ${USE_XDIALOG:+--no-buttons} \ 1551252995Sdteske --infobox "$info_text" $height $width 1552252995Sdteske} 1553252995Sdteske 1554252995Sdteske# f_xdialog_info $info_text ... 1555252995Sdteske# 1556252995Sdteske# Throw up an Xdialog(1) infobox and do not dismiss it until stdin produces 1557252995Sdteske# EOF. This implies that you must execute this either as an rvalue to a pipe, 1558252995Sdteske# lvalue to indirection or in a sub-shell that provides data on stdin. 1559252995Sdteske# 1560252995Sdteskef_xdialog_info() 1561252995Sdteske{ 1562252995Sdteske local info_text="$*" height width 1563252995Sdteske f_dialog_infobox_size height width \ 1564252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text" 1565252995Sdteske $DIALOG \ 1566252995Sdteske --title "$DIALOG_TITLE" \ 1567252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1568252995Sdteske --no-close --no-buttons \ 1569252995Sdteske --infobox "$info_text" $height $width \ 1570252995Sdteske -1 # timeout of -1 means abort when EOF on stdin 1571252995Sdteske} 1572252995Sdteske 1573252995Sdteske############################################################ MSGBOX FUNCTIONS 1574252995Sdteske 1575252995Sdteske# f_dialog_msgbox $msg_text [$hline] 1576252995Sdteske# 1577252995Sdteske# Throw up a dialog(1) msgbox. The msgbox remains until the user presses ENTER 1578252995Sdteske# or ESC, acknowledging the modal dialog. 1579252995Sdteske# 1580252995Sdteske# If the user presses ENTER, the exit status is zero (success), otherwise if 1581252995Sdteske# the user presses ESC the exit status is 255. 1582252995Sdteske# 1583252995Sdteskef_dialog_msgbox() 1584252995Sdteske{ 1585252995Sdteske local msg_text="$1" hline="$2" height width 1586252995Sdteske f_dialog_buttonbox_size height width \ 1587252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline" 1588252995Sdteske $DIALOG \ 1589252995Sdteske --title "$DIALOG_TITLE" \ 1590252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1591252995Sdteske --hline "$hline" \ 1592252995Sdteske --ok-label "$msg_ok" \ 1593252995Sdteske --msgbox "$msg_text" $height $width 1594252995Sdteske} 1595252995Sdteske 1596252995Sdteske############################################################ TEXTBOX FUNCTIONS 1597252995Sdteske 1598252995Sdteske# f_dialog_textbox $file 1599252995Sdteske# 1600252995Sdteske# Display the contents of $file (or an error if $file does not exist, etc.) in 1601252995Sdteske# a dialog(1) textbox (which has a scrollable region for the text). The textbox 1602252995Sdteske# remains until the user presses ENTER or ESC, acknowledging the modal dialog. 1603252995Sdteske# 1604252995Sdteske# If the user presses ENTER, the exit status is zero (success), otherwise if 1605252995Sdteske# the user presses ESC the exit status is 255. 1606252995Sdteske# 1607252995Sdteskef_dialog_textbox() 1608252995Sdteske{ 1609252995Sdteske local file="$1" 1610252995Sdteske local contents height width retval 1611252995Sdteske 1612252995Sdteske contents=$( cat "$file" 2>&1 ) 1613252995Sdteske retval=$? 1614252995Sdteske 1615252995Sdteske f_dialog_buttonbox_size height width \ 1616252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$contents" 1617252995Sdteske 1618252995Sdteske if [ $retval -eq $SUCCESS ]; then 1619252995Sdteske $DIALOG \ 1620252995Sdteske --title "$DIALOG_TITLE" \ 1621252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1622252995Sdteske --exit-label "$msg_ok" \ 1623252995Sdteske --no-cancel \ 1624252995Sdteske --textbox "$file" $height $width 1625252995Sdteske else 1626252995Sdteske $DIALOG \ 1627252995Sdteske --title "$DIALOG_TITLE" \ 1628252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1629252995Sdteske --ok-label "$msg_ok" \ 1630252995Sdteske --msgbox "$contents" $height $width 1631252995Sdteske fi 1632252995Sdteske} 1633252995Sdteske 1634252995Sdteske############################################################ YESNO FUNCTIONS 1635252995Sdteske 1636252995Sdteske# f_dialog_yesno $msg_text [$hline] 1637252995Sdteske# 1638252995Sdteske# Display a dialog(1) Yes/No prompt to allow the user to make some decision. 1639252995Sdteske# The yesno prompt remains until the user presses ENTER or ESC, acknowledging 1640252995Sdteske# the modal dialog. 1641252995Sdteske# 1642252995Sdteske# If the user chooses YES the exit status is zero, or chooses NO the exit 1643252995Sdteske# status is one, or presses ESC the exit status is 255. 1644252995Sdteske# 1645252995Sdteskef_dialog_yesno() 1646252995Sdteske{ 1647252995Sdteske local msg_text="$1" height width 1648252995Sdteske local hline="${2-$hline_arrows_tab_enter}" 1649252995Sdteske 1650252995Sdteske f_interactive || return 0 # If non-interactive, return YES all the time 1651252995Sdteske 1652252995Sdteske f_dialog_buttonbox_size height width \ 1653252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline" 1654252995Sdteske 1655252995Sdteske if [ "$USE_XDIALOG" ]; then 1656252995Sdteske $DIALOG \ 1657252995Sdteske --title "$DIALOG_TITLE" \ 1658252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1659252995Sdteske --hline "$hline" \ 1660252995Sdteske --ok-label "$msg_yes" \ 1661252995Sdteske --cancel-label "$msg_no" \ 1662252995Sdteske --yesno "$msg_text" $height $width 1663252995Sdteske else 1664252995Sdteske $DIALOG \ 1665252995Sdteske --title "$DIALOG_TITLE" \ 1666252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1667252995Sdteske --hline "$hline" \ 1668252995Sdteske --yes-label "$msg_yes" \ 1669252995Sdteske --no-label "$msg_no" \ 1670252995Sdteske --yesno "$msg_text" $height $width 1671252995Sdteske fi 1672252995Sdteske} 1673252995Sdteske 1674252995Sdteske# f_dialog_noyes $msg_text [$hline] 1675252995Sdteske# 1676252995Sdteske# Display a dialog(1) No/Yes prompt to allow the user to make some decision. 1677252995Sdteske# The noyes prompt remains until the user presses ENTER or ESC, acknowledging 1678252995Sdteske# the modal dialog. 1679252995Sdteske# 1680252995Sdteske# If the user chooses YES the exit status is zero, or chooses NO the exit 1681252995Sdteske# status is one, or presses ESC the exit status is 255. 1682252995Sdteske# 1683252995Sdteske# NOTE: This is just like the f_dialog_yesno function except "No" is default. 1684252995Sdteske# 1685252995Sdteskef_dialog_noyes() 1686252995Sdteske{ 1687252995Sdteske local msg_text="$1" height width 1688252995Sdteske local hline="${2-$hline_arrows_tab_enter}" 1689252995Sdteske 1690252995Sdteske f_interactive || return 1 # If non-interactive, return NO all the time 1691252995Sdteske 1692252995Sdteske f_dialog_buttonbox_size height width \ 1693252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline" 1694252995Sdteske 1695252995Sdteske if [ "$USE_XDIALOG" ]; then 1696252995Sdteske $DIALOG \ 1697252995Sdteske --title "$DIALOG_TITLE" \ 1698252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1699252995Sdteske --hline "$hline" \ 1700252995Sdteske --default-no \ 1701252995Sdteske --ok-label "$msg_yes" \ 1702252995Sdteske --cancel-label "$msg_no" \ 1703252995Sdteske --yesno "$msg_text" $height $width 1704252995Sdteske else 1705252995Sdteske $DIALOG \ 1706252995Sdteske --title "$DIALOG_TITLE" \ 1707252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1708252995Sdteske --hline "$hline" \ 1709252995Sdteske --defaultno \ 1710252995Sdteske --yes-label "$msg_yes" \ 1711252995Sdteske --no-label "$msg_no" \ 1712252995Sdteske --yesno "$msg_text" $height $width 1713252995Sdteske fi 1714252995Sdteske} 1715252995Sdteske 1716252995Sdteske############################################################ INPUT FUNCTIONS 1717252995Sdteske 1718252995Sdteske# f_dialog_inputstr_store [-s] $text 1719252995Sdteske# 1720252995Sdteske# Store some text from a dialog(1) inputbox to be retrieved later by 1721252995Sdteske# f_dialog_inputstr_fetch(). If the first argument is `-s', the text is 1722252995Sdteske# sanitized before being stored. 1723252995Sdteske# 1724252995Sdteskef_dialog_inputstr_store() 1725252995Sdteske{ 1726252995Sdteske local sanitize= 1727252995Sdteske [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s 1728252995Sdteske local text="$1" 1729252995Sdteske 1730252995Sdteske # Sanitize the line before storing it if desired 1731252995Sdteske [ "$sanitize" ] && f_dialog_line_sanitize text 1732252995Sdteske 1733252995Sdteske setvar DIALOG_INPUTBOX_$$ "$text" 1734252995Sdteske} 1735252995Sdteske 1736252995Sdteske# f_dialog_inputstr_fetch [$var_to_set] 1737252995Sdteske# 1738252995Sdteske# Obtain the inputstr entered by the user from the most recently displayed 1739252995Sdteske# dialog(1) inputbox (previously stored with f_dialog_inputstr_store() above). 1740252995Sdteske# If $var_to_set is NULL or missing, output is printed to stdout (which is less 1741252995Sdteske# recommended due to performance degradation; in a loop for example). 1742252995Sdteske# 1743252995Sdteskef_dialog_inputstr_fetch() 1744252995Sdteske{ 1745252995Sdteske local __var_to_set="$1" __cp 1746252995Sdteske 1747252995Sdteske debug= f_getvar DIALOG_INPUTBOX_$$ "${__var_to_set:-__cp}" # get data 1748252995Sdteske setvar DIALOG_INPUTBOX_$$ "" # scrub memory in case data was sensitive 1749252995Sdteske 1750252995Sdteske # Return the line on standard-out if desired 1751252995Sdteske [ "$__var_to_set" ] || echo "$__cp" 1752252995Sdteske 1753252995Sdteske return $SUCCESS 1754252995Sdteske} 1755252995Sdteske 1756252995Sdteske# f_dialog_input $var_to_set $prompt [$init [$hline]] 1757252995Sdteske# 1758252995Sdteske# Prompt the user with a dialog(1) inputbox to enter some value. The inputbox 1759252995Sdteske# remains until the the user presses ENTER or ESC, or otherwise ends the 1760252995Sdteske# editing session (by selecting `Cancel' for example). 1761252995Sdteske# 1762252995Sdteske# If the user presses ENTER, the exit status is zero (success), otherwise if 1763252995Sdteske# the user presses ESC the exit status is 255, or if the user chose Cancel, the 1764252995Sdteske# exit status is instead 1. 1765252995Sdteske# 1766252995Sdteske# NOTE: The hline should correspond to the type of data you want from the user. 1767252995Sdteske# NOTE: Should not be used to edit multiline values. 1768252995Sdteske# 1769252995Sdteskef_dialog_input() 1770252995Sdteske{ 1771252995Sdteske local __var_to_set="$1" __prompt="$2" __init="$3" __hline="$4" 1772252995Sdteske 1773252995Sdteske # NOTE: Function name appended to prevent __var_{height,width} values 1774252995Sdteske # from becoming local (and thus preventing setvar from working). 1775252995Sdteske local __height_input __width_input 1776252995Sdteske f_dialog_inputbox_size __height_input __width_input \ 1777252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \ 1778252995Sdteske "$__prompt" "$__init" "$__hline" 1779252995Sdteske 1780252995Sdteske local __opterm="--" 1781252995Sdteske [ "$USE_XDIALOG" ] && __opterm= 1782252995Sdteske 1783252995Sdteske local __dialog_input 1784252995Sdteske __dialog_input=$( 1785252995Sdteske $DIALOG \ 1786252995Sdteske --title "$DIALOG_TITLE" \ 1787252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 1788252995Sdteske --hline "$__hline" \ 1789252995Sdteske --ok-label "$msg_ok" \ 1790252995Sdteske --cancel-label "$msg_cancel" \ 1791252995Sdteske --inputbox "$__prompt" \ 1792252995Sdteske $__height_input $__width_input \ 1793252995Sdteske $__opterm "$__init" \ 1794252995Sdteske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 1795252995Sdteske ) 1796252995Sdteske local __retval=$? 1797252995Sdteske 1798252995Sdteske # Remove warnings and leading/trailing whitespace from user input 1799252995Sdteske f_dialog_line_sanitize __dialog_input 1800252995Sdteske 1801252995Sdteske setvar "$__var_to_set" "$__dialog_input" 1802252995Sdteske return $__retval 1803252995Sdteske} 1804252995Sdteske 1805252995Sdteske############################################################ MENU FUNCTIONS 1806252995Sdteske 1807252995Sdteske# f_dialog_menutag_store [-s] $text 1808252995Sdteske# 1809252995Sdteske# Store some text from a dialog(1) menu to be retrieved later by 1810252995Sdteske# f_dialog_menutag_fetch(). If the first argument is `-s', the text is 1811252995Sdteske# sanitized before being stored. 1812252995Sdteske# 1813252995Sdteskef_dialog_menutag_store() 1814252995Sdteske{ 1815252995Sdteske local sanitize= 1816252995Sdteske [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s 1817252995Sdteske local text="$1" 1818252995Sdteske 1819252995Sdteske # Sanitize the menutag before storing it if desired 1820252995Sdteske [ "$sanitize" ] && f_dialog_data_sanitize text 1821252995Sdteske 1822252995Sdteske setvar DIALOG_MENU_$$ "$text" 1823252995Sdteske} 1824252995Sdteske 1825252995Sdteske# f_dialog_menutag_fetch [$var_to_set] 1826252995Sdteske# 1827252995Sdteske# Obtain the menutag chosen by the user from the most recently displayed 1828252995Sdteske# dialog(1) menu (previously stored with f_dialog_menutag_store() above). If 1829252995Sdteske# $var_to_set is NULL or missing, output is printed to stdout (which is less 1830252995Sdteske# recommended due to performance degradation; in a loop for example). 1831252995Sdteske# 1832252995Sdteskef_dialog_menutag_fetch() 1833252995Sdteske{ 1834252995Sdteske local __var_to_set="$1" __cp 1835252995Sdteske 1836252995Sdteske debug= f_getvar DIALOG_MENU_$$ "${__var_to_set:-__cp}" # get the data 1837252995Sdteske setvar DIALOG_MENU_$$ "" # scrub memory in case data was sensitive 1838252995Sdteske 1839252995Sdteske # Return the data on standard-out if desired 1840252995Sdteske [ "$__var_to_set" ] || echo "$__cp" 1841252995Sdteske 1842252995Sdteske return $SUCCESS 1843252995Sdteske} 1844252995Sdteske 1845252995Sdteske# f_dialog_menuitem_store [-s] $text 1846252995Sdteske# 1847252995Sdteske# Store the item from a dialog(1) menu (see f_dialog_menutag2item()) to be 1848252995Sdteske# retrieved later by f_dialog_menuitem_fetch(). If the first argument is `-s', 1849252995Sdteske# the text is sanitized before being stored. 1850252995Sdteske# 1851252995Sdteskef_dialog_menuitem_store() 1852252995Sdteske{ 1853252995Sdteske local sanitize= 1854252995Sdteske [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s 1855252995Sdteske local text="$1" 1856252995Sdteske 1857252995Sdteske # Sanitize the menuitem before storing it if desired 1858252995Sdteske [ "$sanitize" ] && f_dialog_data_sanitize text 1859252995Sdteske 1860252995Sdteske setvar DIALOG_MENUITEM_$$ "$text" 1861252995Sdteske} 1862252995Sdteske 1863252995Sdteske# f_dialog_menuitem_fetch [$var_to_set] 1864252995Sdteske# 1865252995Sdteske# Obtain the menuitem chosen by the user from the most recently displayed 1866252995Sdteske# dialog(1) menu (previously stored with f_dialog_menuitem_store() above). If 1867252995Sdteske# $var_to_set is NULL or missing, output is printed to stdout (which is less 1868252995Sdteske# recommended due to performance degradation; in a loop for example). 1869252995Sdteske# 1870252995Sdteskef_dialog_menuitem_fetch() 1871252995Sdteske{ 1872252995Sdteske local __var_to_set="$1" __cp 1873252995Sdteske 1874252995Sdteske debug= f_getvar DIALOG_MENUITEM_$$ "${__var_to_set:-__cp}" # get data 1875252995Sdteske setvar DIALOG_MENUITEM_$$ "" # scrub memory in case data was sensitive 1876252995Sdteske 1877252995Sdteske # Return the data on standard-out if desired 1878252995Sdteske [ "$__var_to_set" ] || echo "$__cp" 1879252995Sdteske 1880252995Sdteske return $SUCCESS 1881252995Sdteske} 1882252995Sdteske 1883252995Sdteske# f_dialog_default_store [-s] $text 1884252995Sdteske# 1885252995Sdteske# Store some text to be used later as the --default-item argument to dialog(1) 1886252995Sdteske# (or Xdialog(1)) for --menu, --checklist, and --radiolist widgets. Retrieve 1887252995Sdteske# the text later with f_dialog_menutag_fetch(). If the first argument is `-s', 1888252995Sdteske# the text is sanitized before being stored. 1889252995Sdteske# 1890252995Sdteskef_dialog_default_store() 1891252995Sdteske{ 1892252995Sdteske local sanitize= 1893252995Sdteske [ "$1" = "-s" ] && sanitize=1 && shift 1 # -s 1894252995Sdteske local text="$1" 1895252995Sdteske 1896252995Sdteske # Sanitize the defaulitem before storing it if desired 1897252995Sdteske [ "$sanitize" ] && f_dialog_data_sanitize text 1898252995Sdteske 1899252995Sdteske setvar DEFAULTITEM_$$ "$text" 1900252995Sdteske} 1901252995Sdteske 1902252995Sdteske# f_dialog_default_fetch [$var_to_set] 1903252995Sdteske# 1904252995Sdteske# Obtain text to be used with the --default-item argument of dialog(1) (or 1905252995Sdteske# Xdialog(1)) (previously stored with f_dialog_default_store() above). If 1906252995Sdteske# $var_to_set is NULL or missing, output is printed to stdout (which is less 1907252995Sdteske# recommended due to performance degradation; in a loop for example). 1908252995Sdteske# 1909252995Sdteskef_dialog_default_fetch() 1910252995Sdteske{ 1911252995Sdteske local __var_to_set="$1" __cp 1912252995Sdteske 1913252995Sdteske debug= f_getvar DEFAULTITEM_$$ "${__var_to_set:-__cp}" # get the data 1914252995Sdteske setvar DEFAULTITEM_$$ "" # scrub memory in case data was sensitive 1915252995Sdteske 1916252995Sdteske # Return the data on standard-out if desired 1917252995Sdteske [ "$__var_to_set" ] || echo "$__cp" 1918252995Sdteske 1919252995Sdteske return $SUCCESS 1920252995Sdteske} 1921252995Sdteske 1922252995Sdteske# f_dialog_menutag2item $tag_chosen $tag1 $item1 $tag2 $item2 ... 1923252995Sdteske# 1924252995Sdteske# To use the `--menu' option of dialog(1) you must pass an ordered list of 1925252995Sdteske# tag/item pairs on the command-line. When the user selects a menu option the 1926252995Sdteske# tag for that item is printed to stderr. 1927252995Sdteske# 1928252995Sdteske# This function allows you to dereference the tag chosen by the user back into 1929252995Sdteske# the item associated with said tag. 1930252995Sdteske# 1931252995Sdteske# Pass the tag chosen by the user as the first argument, followed by the 1932252995Sdteske# ordered list of tag/item pairs (HINT: use the same tag/item list as was 1933252995Sdteske# passed to dialog(1) for consistency). 1934252995Sdteske# 1935252995Sdteske# If the tag cannot be found, NULL is returned. 1936252995Sdteske# 1937252995Sdteskef_dialog_menutag2item() 1938252995Sdteske{ 1939252995Sdteske local tag="$1" tagn item 1940252995Sdteske shift 1 # tag 1941252995Sdteske 1942252995Sdteske while [ $# -gt 0 ]; do 1943252995Sdteske tagn="$1" 1944252995Sdteske item="$2" 1945252995Sdteske shift 2 # tagn/item 1946252995Sdteske 1947252995Sdteske if [ "$tag" = "$tagn" ]; then 1948252995Sdteske echo "$item" 1949252995Sdteske return $SUCCESS 1950252995Sdteske fi 1951252995Sdteske done 1952252995Sdteske return $FAILURE 1953252995Sdteske} 1954252995Sdteske 1955252995Sdteske# f_dialog_menutag2item_with_help $tag_chosen $tag1 $item1 $help1 \ 1956252995Sdteske# $tag2 $item2 $help2 ... 1957252995Sdteske# 1958252995Sdteske# To use the `--menu' option of dialog(1) with the `--item-help' option, you 1959252995Sdteske# must pass an ordered list of tag/item/help triplets on the command-line. When 1960252995Sdteske# the user selects a menu option the tag for that item is printed to stderr. 1961252995Sdteske# 1962252995Sdteske# This function allows you to dereference the tag chosen by the user back into 1963252995Sdteske# the item associated with said tag (help is discarded/ignored). 1964252995Sdteske# 1965252995Sdteske# Pass the tag chosen by the user as the first argument, followed by the 1966252995Sdteske# ordered list of tag/item/help triplets (HINT: use the same tag/item/help list 1967252995Sdteske# as was passed to dialog(1) for consistency). 1968252995Sdteske# 1969252995Sdteske# If the tag cannot be found, NULL is returned. 1970252995Sdteske# 1971252995Sdteskef_dialog_menutag2item_with_help() 1972252995Sdteske{ 1973252995Sdteske local tag="$1" tagn item 1974252995Sdteske shift 1 # tag 1975252995Sdteske 1976252995Sdteske while [ $# -gt 0 ]; do 1977252995Sdteske tagn="$1" 1978252995Sdteske item="$2" 1979252995Sdteske shift 3 # tagn/item/help 1980252995Sdteske 1981252995Sdteske if [ "$tag" = "$tagn" ]; then 1982252995Sdteske echo "$item" 1983252995Sdteske return $SUCCESS 1984252995Sdteske fi 1985252995Sdteske done 1986252995Sdteske return $FAILURE 1987252995Sdteske} 1988252995Sdteske 1989252995Sdteske# f_dialog_menutag2index $tag_chosen $tag1 $item1 $tag2 $item2 ... 1990252995Sdteske# 1991252995Sdteske# To use the `--menu' option of dialog(1) you must pass an ordered list of 1992252995Sdteske# tag/item pairs on the command-line. When the user selects a menu option the 1993252995Sdteske# tag for that item is printed to stderr. 1994252995Sdteske# 1995252995Sdteske# This function allows you to dereference the tag chosen by the user back into 1996252995Sdteske# the index associated with said tag. The index is the one-based tag/item pair 1997252995Sdteske# array position within the ordered list of tag/item pairs passed to dialog(1). 1998252995Sdteske# 1999252995Sdteske# Pass the tag chosen by the user as the first argument, followed by the 2000252995Sdteske# ordered list of tag/item pairs (HINT: use the same tag/item list as was 2001252995Sdteske# passed to dialog(1) for consistency). 2002252995Sdteske# 2003252995Sdteske# If the tag cannot be found, NULL is returned. 2004252995Sdteske# 2005252995Sdteskef_dialog_menutag2index() 2006252995Sdteske{ 2007252995Sdteske local tag="$1" tagn n=1 2008252995Sdteske shift 1 # tag 2009252995Sdteske 2010252995Sdteske while [ $# -gt 0 ]; do 2011252995Sdteske tagn="$1" 2012252995Sdteske shift 2 # tagn/item 2013252995Sdteske 2014252995Sdteske if [ "$tag" = "$tagn" ]; then 2015252995Sdteske echo $n 2016252995Sdteske return $SUCCESS 2017252995Sdteske fi 2018252995Sdteske n=$(( $n + 1 )) 2019252995Sdteske done 2020252995Sdteske return $FAILURE 2021252995Sdteske} 2022252995Sdteske 2023252995Sdteske# f_dialog_menutag2index_with_help $tag_chosen $tag1 $item1 $help1 \ 2024252995Sdteske# $tag2 $item2 $help2 ... 2025252995Sdteske# 2026252995Sdteske# To use the `--menu' option of dialog(1) with the `--item-help' option, you 2027252995Sdteske# must pass an ordered list of tag/item/help triplets on the command-line. When 2028252995Sdteske# the user selects a menu option the tag for that item is printed to stderr. 2029252995Sdteske# 2030252995Sdteske# This function allows you to dereference the tag chosen by the user back into 2031252995Sdteske# the index associated with said tag. The index is the one-based tag/item/help 2032252995Sdteske# triplet array position within the ordered list of tag/item/help triplets 2033252995Sdteske# passed to dialog(1). 2034252995Sdteske# 2035252995Sdteske# Pass the tag chosen by the user as the first argument, followed by the 2036252995Sdteske# ordered list of tag/item/help triplets (HINT: use the same tag/item/help list 2037252995Sdteske# as was passed to dialog(1) for consistency). 2038252995Sdteske# 2039252995Sdteske# If the tag cannot be found, NULL is returned. 2040252995Sdteske# 2041252995Sdteskef_dialog_menutag2index_with_help() 2042252995Sdteske{ 2043252995Sdteske local tag="$1" tagn n=1 2044252995Sdteske shift 1 # tag 2045252995Sdteske 2046252995Sdteske while [ $# -gt 0 ]; do 2047252995Sdteske tagn="$1" 2048252995Sdteske shift 3 # tagn/item/help 2049252995Sdteske 2050252995Sdteske if [ "$tag" = "$tagn" ]; then 2051252995Sdteske echo $n 2052252995Sdteske return $SUCCESS 2053252995Sdteske fi 2054252995Sdteske n=$(( $n + 1 )) 2055252995Sdteske done 2056252995Sdteske return $FAILURE 2057252995Sdteske} 2058252995Sdteske 2059252995Sdteske############################################################ INIT FUNCTIONS 2060252995Sdteske 2061252995Sdteske# f_dialog_init 2062252995Sdteske# 2063252995Sdteske# Initialize (or re-initialize) the dialog module after setting/changing any 2064252995Sdteske# of the following environment variables: 2065252995Sdteske# 2066252995Sdteske# USE_XDIALOG Either NULL or Non-NULL. If given a value will indicate 2067252995Sdteske# that Xdialog(1) should be used instead of dialog(1). 2068252995Sdteske# 2069252995Sdteske# SECURE Either NULL or Non-NULL. If given a value will indicate 2070252995Sdteske# that (while running as root) sudo(8) authentication is 2071252995Sdteske# required to proceed. 2072252995Sdteske# 2073253169Sdteske# Also reads ~/.dialogrc for the following information: 2074253169Sdteske# 2075253169Sdteske# NO_SHADOW Either NULL or Non-NULL. If use_shadow is OFF (case- 2076253169Sdteske# insensitive) in ~/.dialogrc this is set to "1" (otherwise 2077253169Sdteske# unset). 2078253169Sdteske# 2079252995Sdteskef_dialog_init() 2080252995Sdteske{ 2081263791Sdteske local funcname=f_dialog_init 2082263791Sdteske 2083252995Sdteske DIALOG_SELF_INITIALIZE= 2084263791Sdteske USE_DIALOG=1 2085252995Sdteske 2086252995Sdteske # 2087252995Sdteske # Clone terminal stdout so we can redirect to it from within sub-shells 2088252995Sdteske # 2089252995Sdteske eval exec $DIALOG_TERMINAL_PASSTHRU_FD\>\&1 2090252995Sdteske 2091252995Sdteske # 2092252995Sdteske # Add `-S' and `-X' to the list of standard arguments supported by all 2093252995Sdteske # 2094252995Sdteske case "$GETOPTS_STDARGS" in 2095252995Sdteske *SX*) : good ;; # already present 2096252995Sdteske *) GETOPTS_STDARGS="${GETOPTS_STDARGS}SX" 2097252995Sdteske esac 2098252995Sdteske 2099252995Sdteske # 2100252995Sdteske # Process stored command-line arguments 2101252995Sdteske # 2102252995Sdteske f_dprintf "f_dialog_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \ 2103252995Sdteske "$ARGV" "$GETOPTS_STDARGS" 2104252995Sdteske SECURE=$( set -- $ARGV 2105252995Sdteske while getopts \ 2106252995Sdteske "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" \ 2107252995Sdteske flag > /dev/null; do 2108252995Sdteske case "$flag" in 2109252995Sdteske S) echo 1 ;; 2110252995Sdteske esac 2111252995Sdteske done 2112252995Sdteske ) 2113252995Sdteske USE_XDIALOG=$( set -- $ARGV 2114252995Sdteske while getopts \ 2115252995Sdteske "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" \ 2116252995Sdteske flag > /dev/null; do 2117252995Sdteske case "$flag" in 2118252995Sdteske S|X) echo 1 ;; 2119252995Sdteske esac 2120252995Sdteske done 2121252995Sdteske ) 2122252995Sdteske f_dprintf "f_dialog_init: SECURE=[%s] USE_XDIALOG=[%s]" \ 2123252995Sdteske "$SECURE" "$USE_XDIALOG" 2124252995Sdteske 2125252995Sdteske # 2126252995Sdteske # Process `-X' command-line option 2127252995Sdteske # 2128263791Sdteske [ "$USE_XDIALOG" ] && DIALOG=Xdialog USE_DIALOG= 2129252995Sdteske 2130252995Sdteske # 2131252995Sdteske # Sanity check, or die gracefully 2132252995Sdteske # 2133252995Sdteske if ! f_have $DIALOG; then 2134252995Sdteske unset USE_XDIALOG 2135252995Sdteske local failed_dialog="$DIALOG" 2136252995Sdteske DIALOG=dialog 2137252995Sdteske f_die 1 "$msg_no_such_file_or_directory" "$pgm" "$failed_dialog" 2138252995Sdteske fi 2139252995Sdteske 2140252995Sdteske # 2141253169Sdteske # Read ~/.dialogrc (unless using Xdialog(1)) for properties 2142253169Sdteske # 2143253169Sdteske if [ -f ~/.dialogrc -a ! "$USE_XDIALOG" ]; then 2144253169Sdteske eval "$( 2145253169Sdteske awk -v param=use_shadow -v expect=OFF \ 2146253169Sdteske -v set="NO_SHADOW=1" ' 2147253169Sdteske !/^[[:space:]]*(#|$)/ && \ 2148253169Sdteske tolower($1) ~ "^"param"(=|$)" && \ 2149253169Sdteske /[^#]*=/ { 2150253169Sdteske sub(/^[^=]*=[[:space:]]*/, "") 2151253169Sdteske if ( toupper($1) == expect ) print set";" 2152253169Sdteske }' ~/.dialogrc 2153253169Sdteske )" 2154253169Sdteske fi 2155253169Sdteske 2156253169Sdteske # 2157252995Sdteske # If we're already running as root but we got there by way of sudo(8) 2158252995Sdteske # and we have X11, we should merge the xauth(1) credentials from our 2159252995Sdteske # original user. 2160252995Sdteske # 2161252995Sdteske if [ "$USE_XDIALOG" ] && 2162252995Sdteske [ "$( id -u )" = "0" ] && 2163252995Sdteske [ "$SUDO_USER" -a "$DISPLAY" ] 2164252995Sdteske then 2165252995Sdteske if ! f_have xauth; then 2166252995Sdteske # Die gracefully, as we [likely] can't use Xdialog(1) 2167252995Sdteske unset USE_XDIALOG 2168252995Sdteske DIALOG=dialog 2169252995Sdteske f_die 1 "$msg_no_such_file_or_directory" "$pgm" "xauth" 2170252995Sdteske fi 2171263791Sdteske HOSTNAME=$( hostname ) 2172252995Sdteske local displaynum="${DISPLAY#*:}" 2173252995Sdteske eval xauth -if \~$SUDO_USER/.Xauthority extract - \ 2174252995Sdteske \"\$HOSTNAME/unix:\$displaynum\" \ 2175252995Sdteske \"\$HOSTNAME:\$displaynum\" | sudo sh -c 'xauth -ivf \ 2176252995Sdteske ~root/.Xauthority merge - > /dev/null 2>&1' 2177252995Sdteske fi 2178252995Sdteske 2179252995Sdteske # 2180252995Sdteske # Probe Xdialog(1) for maximum height/width constraints, or die 2181252995Sdteske # gracefully 2182252995Sdteske # 2183252995Sdteske if [ "$USE_XDIALOG" ]; then 2184252995Sdteske local maxsize 2185263791Sdteske if ! f_eval_catch -dk maxsize $funcname "$DIALOG" \ 2186263791Sdteske 'LANG= LC_ALL= %s --print-maxsize' "$DIALOG" 2187252995Sdteske then 2188252995Sdteske # Xdialog(1) failed, fall back to dialog(1) 2189252995Sdteske unset USE_XDIALOG 2190252995Sdteske 2191252995Sdteske # Display the error message produced by Xdialog(1) 2192252995Sdteske local height width 2193252995Sdteske f_dialog_buttonbox_size height width \ 2194252995Sdteske "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$maxsize" 2195252995Sdteske dialog \ 2196252995Sdteske --title "$DIALOG_TITLE" \ 2197252995Sdteske --backtitle "$DIALOG_BACKTITLE" \ 2198252995Sdteske --ok-label "$msg_ok" \ 2199252995Sdteske --msgbox "$maxsize" $height $width 2200252995Sdteske exit $FAILURE 2201252995Sdteske fi 2202252995Sdteske 2203252995Sdteske XDIALOG_MAXSIZE=$( 2204252995Sdteske set -- ${maxsize##*:} 2205252995Sdteske 2206252995Sdteske height=${1%,} 2207252995Sdteske width=$2 2208252995Sdteske 2209252995Sdteske echo $height $width 2210252995Sdteske ) 2211252995Sdteske fi 2212252995Sdteske 2213252995Sdteske # 2214252995Sdteske # If using Xdialog(1), swap DIALOG_TITLE with DIALOG_BACKTITLE. 2215252995Sdteske # The reason for this is because many dialog(1) applications use 2216252995Sdteske # --backtitle for the program name (which is better suited as 2217252995Sdteske # --title with Xdialog(1)). 2218252995Sdteske # 2219252995Sdteske if [ "$USE_XDIALOG" ]; then 2220252995Sdteske local _DIALOG_TITLE="$DIALOG_TITLE" 2221252995Sdteske DIALOG_TITLE="$DIALOG_BACKTITLE" 2222252995Sdteske DIALOG_BACKTITLE="$_DIALOG_TITLE" 2223252995Sdteske fi 2224252995Sdteske 2225252995Sdteske f_dprintf "f_dialog_init: dialog(1) API initialized." 2226252995Sdteske} 2227252995Sdteske 2228252995Sdteske############################################################ MAIN 2229252995Sdteske 2230252995Sdteske# 2231252995Sdteske# Self-initialize unless requested otherwise 2232252995Sdteske# 2233252995Sdteskef_dprintf "%s: DIALOG_SELF_INITIALIZE=[%s]" \ 2234252995Sdteske dialog.subr "$DIALOG_SELF_INITIALIZE" 2235252995Sdteskecase "$DIALOG_SELF_INITIALIZE" in 2236252995Sdteske""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;; 2237252995Sdteske*) f_dialog_init 2238252995Sdteskeesac 2239252995Sdteske 2240252995Sdteskef_dprintf "%s: Successfully loaded." dialog.subr 2241252995Sdteske 2242252995Sdteskefi # ! $_DIALOG_SUBR 2243