Deleted Added
full compact
dialog.subr (250633) dialog.subr (251190)
1if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1
2#
3# Copyright (c) 2006-2013 Devin Teske
4# All Rights Reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
1if [ ! "$_DIALOG_SUBR" ]; then _DIALOG_SUBR=1
2#
3# Copyright (c) 2006-2013 Devin Teske
4# All Rights Reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: head/usr.sbin/bsdconfig/share/dialog.subr 250633 2013-05-14 03:21:13Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/share/dialog.subr 251190 2013-05-31 19:07:17Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." dialog.subr
34f_include $BSDCFG_SHARE/strings.subr
35f_include $BSDCFG_SHARE/variable.subr

--- 42 unchanged lines hidden (view full) ---

78#
79: ${DIALOG_SELF_INITIALIZE=1}
80
81#
82# Default terminal size (used if/when running without a controlling terminal)
83#
84: ${DEFAULT_TERMINAL_SIZE:=24 80}
85
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." dialog.subr
34f_include $BSDCFG_SHARE/strings.subr
35f_include $BSDCFG_SHARE/variable.subr

--- 42 unchanged lines hidden (view full) ---

78#
79: ${DIALOG_SELF_INITIALIZE=1}
80
81#
82# Default terminal size (used if/when running without a controlling terminal)
83#
84: ${DEFAULT_TERMINAL_SIZE:=24 80}
85
86#
87# Minimum width(s) for various dialog(1) implementations (sensible global
88# default(s) for all widgets of a given variant)
89#
90: ${DIALOG_MIN_WIDTH:=24}
91: ${XDIALOG_MIN_WIDTH:=35}
92
93#
94# When manually sizing Xdialog(1) widgets such as calendar and timebox, you'll
95# need to know the size of the embedded GUI objects because the height passed
96# to Xdialog(1) for these widgets has to be tall enough to accomodate them.
97#
98# These values are helpful when manually sizing with dialog(1) too, but in a
99# different way. dialog(1) does not make you accomodate the custom items in the
100# height (but does for width) -- a height of 3 will display three lines and a
101# full calendar, for example (whereas Xdialog will truncate the calendar if
102# given a height of 3). For dialog(1), use these values for making sure that
103# the height does not exceed max_height (obtained by f_dialog_max_size()).
104#
105DIALOG_CALENDAR_HEIGHT=15
106DIALOG_TIMEBOX_HEIGHT=6
107
86############################################################ GENERIC FUNCTIONS
87
88# f_dialog_title [$new_title]
89#
90# Set the title of future dialog(1) ($DIALOG_TITLE) or backtitle of Xdialog(1)
91# ($DIALOG_BACKTITLE) invocations. If no arguments are given or the first
92# argument is NULL, the current title is returned.
93#

--- 75 unchanged lines hidden (view full) ---

169 DIALOG_TITLE="$_DIALOG_TITLE"
170 else
171 DIALOG_BACKTITLE="$_DIALOG_BACKTITLE"
172 fi
173}
174
175############################################################ SIZE FUNCTIONS
176
108############################################################ GENERIC FUNCTIONS
109
110# f_dialog_title [$new_title]
111#
112# Set the title of future dialog(1) ($DIALOG_TITLE) or backtitle of Xdialog(1)
113# ($DIALOG_BACKTITLE) invocations. If no arguments are given or the first
114# argument is NULL, the current title is returned.
115#

--- 75 unchanged lines hidden (view full) ---

191 DIALOG_TITLE="$_DIALOG_TITLE"
192 else
193 DIALOG_BACKTITLE="$_DIALOG_BACKTITLE"
194 fi
195}
196
197############################################################ SIZE FUNCTIONS
198
177# f_dialog_infobox_size $title $backtitle $prompt [$hline]
199# f_dialog_max_size $var_height $var_width
178#
200#
179# Not all versions of dialog(1) perform auto-sizing of the width and height of
180# `--infobox' boxes sensibly.
201# Get the maximum height and width for a dialog widget and store the values in
202# $var_height and $var_width (respectively).
181#
203#
182# This function helps solve this issue by taking as arguments (in order of
183# appearance) the title, backtitle, prompt, and [optionally] hline returning
184# the optimal width and height for the box (not exceeding the actual terminal
185# width or height).
186#
187# Newline character sequences (``\n'') in $prompt are expanded as-is done by
188# dialog(1).
189#
190# Output is in the format of "height width".
191#
192f_dialog_infobox_size()
204f_dialog_max_size()
193{
205{
194 local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
195 local min_width max_size
196
206 local __var_height="$1" __var_width="$2" __max_size
207 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
197 if [ "$USE_XDIALOG" ]; then
208 if [ "$USE_XDIALOG" ]; then
198 min_width=35
199 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
209 __max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
200 else
210 else
201 min_width=24
202 max_size=$( stty size 2> /dev/null ) # usually "24 80"
203 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
211 __max_size=$( stty size 2> /dev/null ) # usually "24 80"
212 : ${__max_size:=$DEFAULT_TERMINAL_SIZE}
204 fi
213 fi
214 [ "$__var_height" ] && setvar "$__var_height" "${__max_size%%[$IFS]*}"
215 [ "$__var_width" ] && setvar "$__var_width" "${__max_size##*[$IFS]}"
216}
205
217
206 local max_height="${max_size%%[$IFS]*}"
207 local max_width="${max_size##*[$IFS]}"
208 local height width=$min_width
218# f_dialog_size_constrain $var_height $var_width [$min_height [$min_width]]
219#
220# Modify $var_height to be no-less-than $min_height (if given; zero otherwise)
221# and no-greater-than terminal height (or screen height if $USE_XDIALOG is
222# set).
223#
224# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or
225# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal
226# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by
227# passing $min_width.
228#
229# Return status is success unless one of the passed arguments is invalid
230# or all of the $var_* arguments are either NULL or missing.
231#
232f_dialog_size_constrain()
233{
234 local __var_height="$1" __var_width="$2"
235 local __min_height="$3" __min_width="$4"
236 local __retval=$SUCCESS
209
237
238 # Return failure unless at least one var_* argument is passed
239 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
240
210 #
241 #
211 # Bump width for long titles (but don't exceed terminal width).
242 # Print debug warnings if any given (non-NULL) argument are invalid
243 # NOTE: Don't change the name of $__{var,min,}{height,width}
212 #
244 #
213 n=$(( ${#title} + 4 ))
214 if [ $n -gt $width -a $n -gt $min_width ]; then
215 # Add 16.6% width for Xdialog(1)
216 [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 ))
245 local __height __width
246 local __arg __cp __fname=f_dialog_size_constrain
247 for __arg in height width; do
248 debug= f_getvar __var_$__arg __cp
249 [ "$__cp" ] || continue
250 if ! f_getvar "$__cp" __$__arg; then
251 f_dprintf "%s: var_%s variable \`%s' not set" \
252 $__fname $__arg "$__cp"
253 __retval=$FAILURE
254 elif ! eval f_isinteger \$__$__arg; then
255 f_dprintf "%s: var_%s variable value not a number" \
256 $__fname $__arg
257 __retval=$FAILURE
258 fi
259 done
260 for __arg in height width; do
261 debug= f_getvar __min_$__arg __cp
262 [ "$__cp" ] || continue
263 f_isinteger "$__cp" && continue
264 f_dprintf "%s: min_%s value not a number" $__fname $__arg
265 __retval=$FAILURE
266 setvar __min_$__arg ""
267 done
217
268
218 if [ $n -lt $max_width ]; then
219 width=$n
220 else
221 width=$max_width
269 # Obtain maximum height and width values
270 # NOTE: Function name appended to prevent __var_{height,width} values
271 # from becoming local (and thus preventing setvar from working).
272 local __max_height_size_constain __max_width_size_constrain
273 f_dialog_max_size \
274 __max_height_size_constrain __max_width_size_constrain
275
276 # Adjust height if desired
277 if [ "$__var_height" ]; then
278 if [ $__height -lt ${__min_height:-0} ]; then
279 setvar "$__var_height" $__min_height
280 elif [ $__height -gt $__max_height_size_constrain ]; then
281 setvar "$__var_height" $__max_height_size_constrain
222 fi
223 fi
224
282 fi
283 fi
284
225 #
226 # For Xdialog(1), bump width for long backtitles (which appear within
227 # the window; don't exceed maximum width).
228 #
229 if [ "$USE_XDIALOG" ]; then
230 n=$(( ${#btitle} + 4 ))
231 n=$(( $n + $n / 6 ))
232 if [ $n -gt $width -a $n -gt $min_width ]; then
233 if [ $n -lt $max_width ]; then
234 width=$n
235 else
236 width=$max_width
237 fi
285 # Adjust width if desired
286 if [ "$__var_width" ]; then
287 if [ "$USE_XDIALOG" ]; then
288 : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}}
289 else
290 : ${__min_width:=${DIALOG_MIN_WIDTH:-24}}
238 fi
291 fi
292 if [ $__width -lt $__min_width ]; then
293 setvar "$__var_width" $__min_width
294 elif [ $__width -gt $__max_width_size_constrain ]; then
295 setvar "$__var_width" $__max_width_size_constrain
296 fi
239 fi
240
297 fi
298
299 return $__retval # success if no debug warnings were printed
300}
301
302# f_dialog_menu_constrain $var_height $var_width $var_rows "$prompt" \
303# [$min_height [$min_width [$min_rows]]]
304#
305# Modify $var_height to be no-less-than $min_height (if given; zero otherwise)
306# and no-greater-than terminal height (or screen height if $USE_XDIALOG is
307# set).
308#
309# Also modify $var_width to be no-less-than $XDIALOG_MIN_WIDTH (or
310# $XDIALOG_MIN_WIDTH if $_USE_XDIALOG is set) and no-greater-than terminal
311# or screen width. The use of $[X]DIALOG_MIN_WIDTH can be overridden by
312# passing $min_width.
313#
314# Last, modify $var_rows to be no-less-than $min_rows (if specified; zero
315# otherwise) and no-greater-than (max_height - 8) where max_height is the
316# terminal height (or screen height if $USE_XDIALOG is set). If $prompt is NULL
317# or missing, dialog(1) allows $var_rows to be (max_height - 7), maximizing the
318# number of visible rows.
319#
320# Return status is success unless one of the passed arguments is invalid
321# or all of the $var_* arguments are either NULL or missing.
322#
323f_dialog_menu_constrain()
324{
325 local __var_height="$1" __var_width="$2" __var_rows="$3" __prompt="$4"
326 local __min_height="$5" __min_width="$6" __min_rows="$7"
327
328 # Return failure unless at least one var_* argument is passed
329 [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
330 return $FAILURE
331
241 #
332 #
242 # Bump width for long prompts (if not already at maximum width).
333 # Print debug warnings if any given (non-NULL) argument are invalid
334 # NOTE: Don't change the name of $__{var,min,}{height,width,rows}
243 #
335 #
244 if [ $width -lt $max_width ]; then
245 n=$( echo "$prompt" | f_longest_line_length )
246 n=$(( $n + 4 ))
336 local __height __width __rows
337 local __arg __cp __fname=f_dialog_menu_constrain
338 for __arg in height width rows; do
339 debug= f_getvar __var_$__arg __cp
340 [ "$__cp" ] || continue
341 if ! f_getvar "$__cp" __$__arg; then
342 f_dprintf "%s: var_%s variable \`%s' not set" \
343 $__fname $__arg "$__cp"
344 __retval=$FAILURE
345 elif ! eval f_isinteger \$__$__arg; then
346 f_dprintf "%s: var_%s variable value not a number" \
347 $__fname $__arg
348 __retval=$FAILURE
349 fi
350 done
351 for __arg in height width rows; do
352 debug= f_getvar __min_$__arg __cp
353 [ "$__cp" ] || continue
354 f_isinteger "$__cp" && continue
355 f_dprintf "%s: min_%s value not a number" $__fname $__arg
356 __retval=$FAILURE
357 setvar __min_$__arg ""
358 done
247
359
248 # Add 16.6% width for Xdialog(1)
249 [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 ))
360 # Obtain maximum height and width values
361 # NOTE: Function name appended to prevent __var_{height,width} values
362 # from becoming local (and thus preventing setvar from working).
363 local __max_height_menu_constrain __max_width_menu_constrain
364 f_dialog_max_size \
365 __max_height_menu_constrain __max_width_menu_constrain
250
366
251 if [ $n -gt $width -a $n -gt $min_width ]; then
252 if [ $n -lt $max_width ]; then
253 width=$n
254 else
255 width=$max_width
256 fi
367 # Adjust height if desired
368 if [ "$__var_height" ]; then
369 if [ $__height -lt ${__min_height:-0} ]; then
370 setvar "$__var_height" $__min_height
371 elif [ $__height -gt $__max_height_menu_constrain ]; then
372 setvar "$__var_height" $__max_height_menu_constrain
257 fi
258 fi
259
373 fi
374 fi
375
260 #
261 # Bump width for long hlines (if not already at maximum width).
262 # NOTE: Though Xdialog(1) supports `--hline', it's not currently used.
263 #
264 if [ ! "$USE_XDIALOG" ]; then
265 if [ $width -lt $max_width ]; then
266 n=$(( ${#hline} + 10 ))
267 if [ $n -gt $width -a $n -gt $min_width ]; then
268 if [ $n -lt $max_width ]; then
269 width=$n
270 else
271 width=$max_width
272 fi
273 fi
376 # Adjust width if desired
377 if [ "$__var_width" ]; then
378 if [ "$USE_XDIALOG" ]; then
379 : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}}
380 else
381 : ${__min_width:=${DIALOG_MIN_WIDTH:-24}}
274 fi
382 fi
383 if [ $__width -lt $__min_width ]; then
384 setvar "$__var_width" $__min_width
385 elif [ $__width -gt $__max_width_menu_constrain ]; then
386 setvar "$__var_width" $__max_width_menu_constrain
387 fi
275 fi
276
388 fi
389
277 #
278 # Set height based on number of rows in prompt
279 #
280 height=$( echo -n "$prompt" | f_number_of_lines )
281 height=$(( $height + 2 ))
390 # Adjust rows if desired
391 if [ "$__var_rows" ]; then
392 if [ "$USE_XDIALOG" ]; then
393 : ${__min_rows:=1}
394 else
395 : ${__min_rows:=0}
396 fi
282
397
283 #
284 # For Xdialog(1) bump height if backtitle is enabled (displayed in the
285 # X11 window with a separator line between the backtitle and msg text)
286 #
287 if [ "$USE_XDIALOG" -a "$btitle" ]; then
288 n=$( echo "$btitle" | f_number_of_lines )
289 height=$(( $height + $n + 2 ))
398 local __max_rows=$(( $__max_height_menu_constrain - 8 ))
399 # If prompt_len is zero (no prompt), bump the max-rows by 1
400 # Default assumption is (if no argument) that there's no prompt
401 [ ${__prompt_len:-0} -gt 0 ] ||
402 __max_rows=$(( $__max_rows + 1 ))
403
404 if [ $__rows -lt $__min_rows ]; then
405 setvar "$__var_rows" $__min_rows
406 elif [ $__rows -gt $__max_rows ]; then
407 setvar "$__var_rows" $__max_rows
408 fi
290 fi
291
409 fi
410
292 # Make sure height is less than maximum screen size
293 [ $height -le $max_height ] || height=$max_height
411 return $__retval # success if no debug warnings were printed
412}
294
413
295 # Return both
296 echo "$height $width"
414# f_dialog_infobox_size [-n] $var_height $var_width \
415# $title $backtitle $prompt [$hline]
416#
417# Not all versions of dialog(1) perform auto-sizing of the width and height of
418# `--infobox' boxes sensibly.
419#
420# This function helps solve this issue by taking two sets of sequential
421# arguments. The first set of arguments are the variable names to use when
422# storing the calculated height and width. The second set of arguments are the
423# title, backtitle, prompt, and [optionally] hline. The optimal height and
424# width for the described widget (not exceeding the actual terminal height or
425# width) is stored in $var_height and $var_width (respectively).
426#
427# If the first argument is `-n', the calculated sizes ($var_height and
428# $var_width) are not constrained to minimum/maximum values.
429#
430# Newline character sequences (``\n'') in $prompt are expanded as-is done by
431# dialog(1).
432#
433f_dialog_infobox_size()
434{
435 local __constrain=1
436 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
437 local __var_height="$1" __var_width="$2"
438 local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
439
440 # Return unless at least one size aspect has been requested
441 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
442
443 # Default height/width of zero for auto-sizing
444 local __height=0 __width=0 __n
445
446 # Adjust height if desired
447 if [ "$__var_height" ]; then
448 #
449 # Set height based on number of rows in prompt
450 #
451 __n=$( echo -n "$__prompt" | f_number_of_lines )
452 __n=$(( $__n + 2 ))
453 [ $__n -gt $__height ] && __height=$__n
454
455 #
456 # For Xdialog(1) bump height if backtitle is enabled (displayed
457 # in the X11 window with a separator line between the backtitle
458 # and msg text).
459 #
460 if [ "$USE_XDIALOG" -a "$__btitle" ]; then
461 __n=$( echo "$__btitle" | f_number_of_lines )
462 __height=$(( $__height + $__n + 2 ))
463 fi
464
465 setvar "$__var_height" $__height
466 fi
467
468 # Adjust width if desired
469 if [ "$__var_width" ]; then
470 #
471 # Bump width for long titles
472 #
473 __n=$(( ${#__title} + 4 ))
474 [ $__n -gt $__width ] && __width=$__n
475
476 #
477 # If using Xdialog(1), bump width for long backtitles (which
478 # appear within the window).
479 #
480 if [ "$USE_XDIALOG" ]; then
481 __n=$(( ${#__btitle} + 4 ))
482 [ $__n -gt $__width ] && __width=$__n
483 fi
484
485 #
486 # Bump width for long prompts
487 #
488 __n=$( echo "$__prompt" | f_longest_line_length )
489 __n=$(( $__n + 4 )) # add width for border
490 [ $__n -gt $__width ] && __width=$__n
491
492 #
493 # Bump width for long hlines. Xdialog(1) supports `--hline' but
494 # it's currently not used (so don't do anything here if using
495 # Xdialog(1)).
496 #
497 if [ ! "$USE_XDIALOG" ]; then
498 __n=$(( ${#__hline} + 10 ))
499 [ $__n -gt $__width ] && __width=$__n
500 fi
501
502 # Bump width by 16.6% if using Xdialog(1)
503 [ "$USE_XDIALOG" ] && __width=$(( $__width + $__width / 6 ))
504
505 setvar "$__var_width" $__width
506 fi
507
508 # Constrain values to sensible minimums/maximums unless `-n' was passed
509 # Return success if no-constrain, else return status from constrain
510 [ ! "$__constrain" ] ||
511 f_dialog_size_constrain "$__var_height" "$__var_width"
297}
298
512}
513
299# f_dialog_buttonbox_size $title $backtitle $prompt [$hline]
514# f_dialog_buttonbox_size [-n] $var_height $var_width \
515# $title $backtitle $prompt [$hline]
300#
301# Not all versions of dialog(1) perform auto-sizing of the width and height of
302# `--msgbox' and `--yesno' boxes sensibly.
303#
516#
517# Not all versions of dialog(1) perform auto-sizing of the width and height of
518# `--msgbox' and `--yesno' boxes sensibly.
519#
304# This function helps solve this issue by taking as arguments (in order of
305# appearance) the title, backtitle, prompt, and [optionally] hline returning
306# the optimal width and height for the box (not exceeding the actual terminal
307# width or height).
520# This function helps solve this issue by taking two sets of sequential
521# arguments. The first set of arguments are the variable names to use when
522# storing the calculated height and width. The second set of arguments are the
523# title, backtitle, prompt, and [optionally] hline. The optimal height and
524# width for the described widget (not exceeding the actual terminal height or
525# width) is stored in $var_height and $var_width (respectively).
308#
526#
527# If the first argument is `-n', the calculated sizes ($var_height and
528# $var_width) are not constrained to minimum/maximum values.
529#
309# Newline character sequences (``\n'') in $prompt are expanded as-is done by
310# dialog(1).
311#
530# Newline character sequences (``\n'') in $prompt are expanded as-is done by
531# dialog(1).
532#
312# Output is in the format of "height width".
313#
314f_dialog_buttonbox_size()
315{
533f_dialog_buttonbox_size()
534{
316 local title="$1" btitle="$2" prompt="$3" hline="$4"
317 local size="$( f_dialog_infobox_size \
318 "$title" "$btitle" "$prompt" "$hline" )"
319 local height="${size%%[$IFS]*}"
320 local width="${size##*[$IFS]}"
535 local __constrain=1
536 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
537 local __var_height="$1" __var_width="$2"
538 local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
321
539
322 # Add height to accomodate the buttons
323 height=$(( $height + 2 ))
540 # Return unless at least one size aspect has been requested
541 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
324
542
325 # Adjust for clipping with Xdialog(1) on Linux/GTK2
326 [ "$USE_XDIALOG" ] && height=$(( $height + 3 ))
543 # Calculate height/width of infobox (adjusted/constrained below)
544 # NOTE: Function name appended to prevent __var_{height,width} values
545 # from becoming local (and thus preventing setvar from working).
546 local __height_bbox_size __width_bbox_size
547 f_dialog_infobox_size -n \
548 "${__var_height:+__height_bbox_size}" \
549 "${__var_width:+__width_bbox_size}" \
550 "$__title" "$__btitle" "$__prompt" "$__hline"
327
551
328 #
329 # Enforce maximum height regardless
330 #
331 local max_size
332 if [ "$USE_XDIALOG" ]; then
333 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
334 else
335 max_size=$( stty size 2> /dev/null ) # usually "24 80"
336 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
552 # Adjust height if desired
553 if [ "$__var_height" ]; then
554 # Add height to accomodate the buttons
555 __height_bbox_size=$(( $__height_bbox_size + 2 ))
556
557 # Adjust for clipping with Xdialog(1) on Linux/GTK2
558 [ "$USE_XDIALOG" ] &&
559 __height_bbox_size=$(( $__height_bbox_size + 3 ))
560
561 setvar "$__var_height" $__height_bbox_size
337 fi
562 fi
338 local max_height="${max_size%%[$IFS]*}"
339 [ $height -le $max_height ] || height=$max_height
340
563
341 # Return both
342 echo "$height $width"
564 # No adjustemnts to width, just pass-thru the infobox width
565 if [ "$__var_width" ]; then
566 setvar "$__var_width" $__width_bbox_size
567 fi
568
569 # Constrain values to sensible minimums/maximums unless `-n' was passed
570 # Return success if no-constrain, else return status from constrain
571 [ ! "$__constrain" ] ||
572 f_dialog_size_constrain "$__var_height" "$__var_width"
343}
344
573}
574
345# f_dialog_inputbox_size $title $backtitle $prompt $init [$hline]
575# f_dialog_inputbox_size [-n] $var_height $var_width \
576# $title $backtitle $prompt $init [$hline]
346#
347# Not all versions of dialog(1) perform auto-sizing of the width and height of
348# `--inputbox' boxes sensibly.
349#
577#
578# Not all versions of dialog(1) perform auto-sizing of the width and height of
579# `--inputbox' boxes sensibly.
580#
350# This function helps solve this issue by taking as arguments (in order of
351# appearance) the title, backtitle, prompt, initial text, and [optionally]
352# hline returning the optimal width and height for the box (not exceeding the
353# actual terminal width and height).
581# This function helps solve this issue by taking two sets of sequential
582# arguments. The first set of arguments are the variable names to use when
583# storing the calculated height and width. The second set of arguments are the
584# title, backtitle, prompt, and [optionally] hline. The optimal height and
585# width for the described widget (not exceeding the actual terminal height or
586# width) is stored in $var_height and $var_width (respectively).
354#
587#
588# If the first argument is `-n', the calculated sizes ($var_height and
589# $var_width) are not constrained to minimum/maximum values.
590#
355# Newline character sequences (``\n'') in $prompt are expanded as-is done by
356# dialog(1).
357#
591# Newline character sequences (``\n'') in $prompt are expanded as-is done by
592# dialog(1).
593#
358# Output is in the format of "height width".
359#
360f_dialog_inputbox_size()
361{
594f_dialog_inputbox_size()
595{
362 local title="$1" btitle="$2" prompt="$3" init="$4" hline="$5" n
363 local size="$( f_dialog_buttonbox_size \
364 "$title" "$btitle" "$prompt" "$hline" )"
365 local height="${size%%[$IFS]*}"
366 local width="${size##*[$IFS]}"
596 local __constrain=1
597 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
598 local __var_height="$1" __var_width="$2"
599 local __title="$3" __btitle="$4" __prompt="$5" __init="$6" __hline="$7"
367
600
368 local min_width max_size
369 if [ "$USE_XDIALOG" ]; then
370 min_width=35
371 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
372 else
373 min_width=24
374 max_size=$( stty size 2> /dev/null ) # usually "24 80"
375 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
376 fi
377 local max_height="${max_size%%[$IFS]*}"
378 local max_width="${max_size##*[$IFS]}"
601 # Return unless at least one size aspect has been requested
602 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
379
603
380 #
381 # Add height to accomodate the input box
382 #
383 [ ! "$USE_XDIALOG" ] && height=$(( $height + 3 ))
384 [ $height -le $max_height ] || height=$max_height
604 # Calculate height/width of buttonbox (adjusted/constrained below)
605 # NOTE: Function name appended to prevent __var_{height,width} values
606 # from becoming local (and thus preventing setvar from working).
607 local __height_ibox_size __width_ibox_size
608 f_dialog_buttonbox_size -n \
609 "${__var_height:+__height_ibox_size}" \
610 "${__var_width:+__width_ibox_size}" \
611 "$__title" "$__btitle" "$__prompt" "$__hline"
385
612
386 #
387 # Bump width for initial text (if not already at maximum width).
388 # NOTE: Something neither dialog(1)/Xdialog(1) do, but worth it!
389 #
390 if [ $width -lt $max_width ]; then
391 n=$(( ${#init} + 7 ))
613 # Adjust height if desired
614 if [ "$__var_height" ]; then
615 # Add height for input box (not needed for Xdialog(1))
616 [ ! "$USE_XDIALOG" ] &&
617 __height_ibox_size=$(( $__height_ibox_size + 3 ))
392
618
393 # Add 16.6% width for Xdialog(1)
394 [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 ))
619 setvar "$__var_height" $__height_ibox_size
620 fi
395
621
396 if [ $n -gt $width -a $n -gt $min_width ]; then
397 if [ $n -lt $max_width ]; then
398 width=$n
399 else
400 width=$max_width
401 fi
402 fi
622 # Adjust width if desired
623 if [ "$__var_width" ]; then
624 # Bump width for initial text (something neither dialog(1) nor
625 # Xdialog(1) do, but worth it!; add 16.6% if using Xdialog(1))
626 local __n=$(( ${#__init} + 7 ))
627 [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 ))
628 [ $__n -gt $__width_ibox_size ] && __width_ibox_size=$__n
629
630 setvar "$__var_width" $__width_ibox_size
403 fi
404
631 fi
632
405 # Return both
406 echo "$height $width"
633 # Constrain values to sensible minimums/maximums unless `-n' was passed
634 # Return success if no-constrain, else return status from constrain
635 [ ! "$__constrain" ] ||
636 f_dialog_size_constrain "$__var_height" "$__var_width"
407}
408
637}
638
409# f_xdialog_2inputsbox_size $title $backtitle $prompt \
639# f_xdialog_2inputsbox_size [-n] $var_height $var_width \
640# $title $backtitle $prompt \
410# $label1 $init1 $label2 $init2
411#
412# Xdialog(1) does not perform auto-sizing of the width and height of
413# `--2inputsbox' boxes sensibly.
414#
641# $label1 $init1 $label2 $init2
642#
643# Xdialog(1) does not perform auto-sizing of the width and height of
644# `--2inputsbox' boxes sensibly.
645#
415# This function helps solve this issue by taking as arguments (in order of
416# appearance) the title, backtitle, prompt, label for the first field, initial
417# text for said field, label for the second field, and initial text for said
418# field returning the optimal width and height for the box (not exceeding the
419# actual terminal width and height).
646# This function helps solve this issue by taking two sets of sequential
647# arguments. The first set of arguments are the variable names to use when
648# storing the calculated height and width. The second set of arguments are the
649# title, backtitle, prompt, label for the first field, initial text for said
650# field, label for the second field, and initial text for said field. The
651# optimal height and width for the described widget (not exceeding the actual
652# terminal height or width) is stored in $var_height and $var_width
653# (respectively).
420#
654#
655# If the first argument is `-n', the calculated sizes ($var_height and
656# $var_width) are not constrained to minimum/maximum values.
657#
421# Newline character sequences (``\n'') in $prompt are expanded as-is done by
422# Xdialog(1).
423#
658# Newline character sequences (``\n'') in $prompt are expanded as-is done by
659# Xdialog(1).
660#
424# Output is in the format of "height width".
425#
426f_xdialog_2inputsbox_size()
427{
661f_xdialog_2inputsbox_size()
662{
428 local title="$1" btitle="$2" prompt="$3"
429 local label1="$4" init1="$5" label2="$6" init2="$7" n
430 local size="$( f_dialog_inputbox_size \
431 "$title" "$btitle" "$prompt" "$init1" )"
432 local height="${size%%[$IFS]*}"
433 local width="${size##*[$IFS]}"
663 local __constrain=1
664 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
665 local __var_height="$1" __var_width="$2"
666 local __title="$3" __btitle="$4" __prompt="$5"
667 local __label1="$6" __init1="$7" __label2="$8" __init2="$9"
434
668
435 local min_width=35
436 local max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
437 local max_height="${max_size%%[$IFS]*}"
438 local max_width="${max_size##*[$IFS]}"
669 # Return unless at least one size aspect has been requested
670 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
439
671
440 # Add height for first label
441 height=$(( $height + 2 ))
442
443 #
444 # Bump width for first label text (if not already at maximum width).
445 #
446 if [ $width -lt $max_width ]; then
447 n=$(( ${#label1} + 7 ))
448
449 # Add 16.6% width for Xdialog(1)
450 n=$(( $n + $n / 6 ))
451
452 if [ $n -gt $width -a $n -gt $min_width ]; then
453 if [ $n -lt $max_width ]; then
454 width=$n
455 else
456 width=$max_width
457 fi
458 fi
672 # Calculate height/width of inputbox (adjusted/constrained below)
673 # NOTE: Function name appended to prevent __var_{height,width} values
674 # from becoming local (and thus preventing setvar from working).
675 local __height_2ibox_size __width_2ibox_size
676 f_dialog_inputbox_size -n \
677 "${__var_height:+__height_2ibox_size}" \
678 "${__var_width:+__width_2ibox_size}" \
679 "$__title" "$__btitle" "$__prompt" "$__hline" "$__init1"
680
681 # Adjust height if desired
682 if [ "$__var_height" ]; then
683 # Add height for 1st label, 2nd label, and 2nd input box
684 __height_2ibox_size=$(( $__height_2ibox_size + 2 + 2 + 2 ))
685 setvar "$__var_height" $__height_2ibox_size
459 fi
460
686 fi
687
461 # Add height for second label
462 height=$(( $height + 2 ))
688 # Adjust width if desired
689 if [ "$__var_width" ]; then
690 local __n
463
691
464 #
465 # Bump width for second label text (if not already at maximum width).
466 #
467 if [ $width -lt $max_width ]; then
468 n=$(( ${#label2} + 7 ))
692 # Bump width for first label text (+16.6% since Xdialog(1))
693 __n=$(( ${#__label1} + 7 ))
694 __n=$(( $__n + $__n / 6 ))
695 [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n
469
696
470 # Add 16.6% width for Xdialog(1)
471 n=$(( $n + $n / 6 ))
697 # Bump width for second label text (+16.6% since Xdialog(1))
698 __n=$(( ${#__label2} + 7 ))
699 __n=$(( $__n + $__n / 6 ))
700 [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n
472
701
473 if [ $n -gt $width -a $n -gt $min_width ]; then
474 if [ $n -lt $max_width ]; then
475 width=$n
476 else
477 width=$max_width
478 fi
479 fi
480 fi
702 # Bump width for 2nd initial text (something neither dialog(1)
703 # nor Xdialog(1) do, but worth it!; +16.6% since Xdialog(1))
704 __n=$(( ${#__init2} + 7 ))
705 __n=$(( $__n + $__n / 6 ))
706 [ $__n -gt $__width_2ibox_size ] && __width_2ibox_size=$__n
481
707
482 # Add height for a second inputbox
483 height=$(( $height + 2 ))
484 [ $height -le $max_height ] || height=$max_height
485
486 #
487 # Bump width for second initial text (if not already at maximum width).
488 # NOTE: Something neither dialog(1)/Xdialog(1) do, but worth it!
489 #
490 if [ $width -lt $max_width ]; then
491 n=$(( ${#init2} + 7 ))
492
493 # Add 16.6% width for Xdialog(1)
494 n=$(( $n + $n / 6 ))
495
496 if [ $n -gt $width -a $n -gt $min_width ]; then
497 if [ $n -lt $max_width ]; then
498 width=$n
499 else
500 width=$max_width
501 fi
502 fi
708 setvar "$__var_width" $__width_2ibox_size
503 fi
504
709 fi
710
505 # Return both
506 echo "$height $width"
711 # Constrain values to sensible minimums/maximums unless `-n' was passed
712 # Return success if no-constrain, else return status from constrain
713 [ ! "$__constrain" ] ||
714 f_dialog_size_constrain "$__var_height" "$__var_width"
507}
508
715}
716
509# f_dialog_menu_size $title $backtitle $prompt $hline \
717# f_dialog_menu_size [-n] $var_height $var_width $var_rows \
718# $title $backtitle $prompt $hline \
510# $tag1 $item1 $tag2 $item2 ...
511#
512# Not all versions of dialog(1) perform auto-sizing of the width and height of
513# `--menu' boxes sensibly.
514#
719# $tag1 $item1 $tag2 $item2 ...
720#
721# Not all versions of dialog(1) perform auto-sizing of the width and height of
722# `--menu' boxes sensibly.
723#
515# This function helps solve this issue by taking as arguments (in order of
516# appearance) the title, backtitle, prompt, hline and list of tag/item pairs,
517# returning the optimal width and height for the menu (not exceeding the actual
518# terminal width or height).
724# This function helps solve this issue by taking three sets of sequential
725# arguments. The first set of arguments are the variable names to use when
726# storing the calculated height, width, and rows. The second set of arguments
727# are the title, backtitle, prompt, and hline. The [optional] third set of
728# arguments are the menu list itself (comprised of tag/item couplets). The
729# optimal height, width, and rows for the described widget (not exceeding the
730# actual terminal height or width) is stored in $var_height, $var_width, and
731# $var_rows (respectively).
519#
732#
520# Output is in the format of "height width rows".
733# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
734# and $var_rows) are not constrained to minimum/maximum values.
521#
522f_dialog_menu_size()
523{
735#
736f_dialog_menu_size()
737{
524 local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
525 local min_width min_rows max_size
738 local __constrain=1
739 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
740 local __var_height="$1" __var_width="$2" __var_rows="$3"
741 local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
742 shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
526
743
527 if [ "$USE_XDIALOG" ]; then
528 min_width=35
529 min_rows=1
530 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
531 else
532 min_width=24
533 min_rows=0
534 max_size=$( stty size 2> /dev/null ) # usually "24 80"
535 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
536 fi
744 # Return unless at least one size aspect has been requested
745 [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
746 return $FAILURE
537
747
538 local max_width="${max_size##*[$IFS]}"
539 local max_height="${max_size%%[$IFS]*}"
540 local box_size="$( f_dialog_infobox_size \
541 "$title" "$btitle" "$prompt" "$hline" )"
542 local box_height="${box_size%%[$IFS]*}"
543 local box_width="${box_size##*[$IFS]}"
544 local max_rows=$(( $max_height - 8 ))
545 local height width=$box_width rows=$min_rows
748 # Calculate height/width of infobox (adjusted/constrained below)
749 # NOTE: Function name appended to prevent __var_{height,width} values
750 # from becoming local (and thus preventing setvar from working).
751 local __height_menu_size __width_menu_size
752 f_dialog_infobox_size -n \
753 "${__var_height:+__height_menu_size}" \
754 "${__var_width:+__width_menu_size}" \
755 "$__title" "$__btitle" "$__prompt" "$__hline"
546
756
547 shift 4 # title/btitle/prompt/hline
548
549 # If there's no prompt, bump the max-rows by 1
550 [ "$prompt" ] || max_rows=$(( $max_rows + 1 ))
551
552 #
757 #
553 # The sum total between the longest tag-length and longest item-length
554 # should be used for the menu width (not to exceed terminal width).
758 # Always process the menu-item arguments to get the longest tag-length,
759 # longest item-length (both used to bump the width), and the number of
760 # rows (used to bump the height).
555 #
761 #
556 # Also, calculate the number of rows (not to exceed terminal height).
557 #
558 local longest_tag=0 longest_item=0
762 local __longest_tag=0 __longest_item=0 __rows=0
559 while [ $# -ge 2 ]; do
763 while [ $# -ge 2 ]; do
560 local tag="$1" item="$2"
764 local __tag="$1" __item="$2"
561 shift 2 # tag/item
765 shift 2 # tag/item
562
563 [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag}
564 [ ${#item} -gt $longest_item ] && longest_item=${#item}
565 [ $rows -lt $max_rows ] && rows=$(( $rows + 1 ))
766 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
767 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
768 __rows=$(( $__rows + 1 ))
566 done
567
769 done
770
568 # Update width
569 n=$(( $longest_tag + $longest_item + 10 ))
570 [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1)
571 if [ $n -gt $width -a $n -gt $min_width ]; then
572 if [ $n -lt $max_width ]; then
573 width=$n
771 # Adjust rows early (for up-comning height calculation)
772 if [ "$__var_height" -o "$__var_rows" ]; then
773 # Add a row for visual aid if using Xdialog(1)
774 [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
775 fi
776
777 # Adjust height if desired
778 if [ "$__var_height" ]; then
779 # Add rows to height
780 if [ "$USE_XDIALOG" ]; then
781 __height_menu_size=$((
782 $__height_menu_size + $__rows + 7 ))
574 else
783 else
575 width=$max_width
784 __height_menu_size=$((
785 $__height_menu_size + $__rows + 4 ))
576 fi
786 fi
787 setvar "$__var_height" $__height_menu_size
577 fi
578
788 fi
789
579 # Fix rows and set height
580 [ $rows -gt 0 ] || rows=1
581 if [ "$USE_XDIALOG" ]; then
582 height=$(( $rows + $box_height + 7 ))
583 else
584 height=$(( $rows + $box_height + 4 ))
790 # Adjust width if desired
791 if [ "$__var_width" ]; then
792 # The sum total between the longest tag-length and the
793 # longest item-length should be used to bump menu width
794 local __n=$(( $__longest_tag + $__longest_item + 10 ))
795 [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
796 [ $__n -gt $__width_menu_size ] && __width_menu_size=$__n
797
798 setvar "$__var_width" $__width_menu_size
585 fi
799 fi
586 [ $height -le $max_height ] || height=$max_height
587
800
588 # Return all three
589 echo "$height $width $rows"
801 # Store adjusted rows if desired
802 [ "$__var_rows" ] && setvar "$__var_rows" $__rows
803
804 # Constrain height, width, and rows to sensible minimum/maximum values
805 # Return success if no-constrain, else return status from constrain
806 [ ! "$__constrain" ] || f_dialog_menu_constrain \
807 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
590}
591
808}
809
592# f_dialog_menu_with_help_size $title $backtitle $prompt $hline \
810# f_dialog_menu_with_help_size [-n] $var_height $var_width $var_rows \
811# $title $backtitle $prompt $hline \
593# $tag1 $item1 $help1 $tag2 $item2 $help2 ...
594#
595# Not all versions of dialog(1) perform auto-sizing of the width and height of
596# `--menu' boxes sensibly.
597#
812# $tag1 $item1 $help1 $tag2 $item2 $help2 ...
813#
814# Not all versions of dialog(1) perform auto-sizing of the width and height of
815# `--menu' boxes sensibly.
816#
598# This function helps solve this issue by taking as arguments (in order of
599# appearance) the title, backtitle, prompt, hline and list of tag/item/help
600# triplets, returning the optimal width and height for the menu (not exceeding
601# the actual terminal width or height).
817# This function helps solve this issue by taking three sets of sequential
818# arguments. The first set of arguments are the variable names to use when
819# storing the calculated height, width, and rows. The second set of arguments
820# are the title, backtitle, prompt, and hline. The [optional] third set of
821# arguments are the menu list itself (comprised of tag/item/help triplets). The
822# optimal height, width, and rows for the described widget (not exceeding the
823# actual terminal height or width) is stored in $var_height, $var_width, and
824# $var_rows (respectively).
602#
825#
603# Output is in the format of "height width rows".
826# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
827# and $var_rows) are not constrained to minimum/maximum values.
604#
605f_dialog_menu_with_help_size()
606{
828#
829f_dialog_menu_with_help_size()
830{
607 local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
608 local min_width min_rows max_size
831 local __constrain=1
832 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
833 local __var_height="$1" __var_width="$2" __var_rows="$3"
834 local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
835 shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
609
836
610 if [ "$USE_XDIALOG" ]; then
611 min_width=35
612 min_rows=1
613 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
614 else
615 min_width=24
616 min_rows=0
617 max_size=$( stty size 2> /dev/null ) # usually "24 80"
618 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
619 fi
837 # Return unless at least one size aspect has been requested
838 [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
839 return $FAILURE
620
840
621 local max_width="${max_size##*[$IFS]}"
622 local max_height="${max_size%%[$IFS]*}"
623 local box_size="$( f_dialog_infobox_size \
624 "$title" "$btitle" "$prompt" "$hline" )"
625 local box_height="${box_size%%[$IFS]*}"
626 local box_width="${box_size##*[$IFS]}"
627 local max_rows=$(( $max_height - 8 ))
628 local height width=$box_width rows=$min_rows
841 # Calculate height/width of infobox (adjusted/constrained below)
842 # NOTE: Function name appended to prevent __var_{height,width} values
843 # from becoming local (and thus preventing setvar from working).
844 local __height_menu_with_help_size __width_menu_with_help_size
845 f_dialog_infobox_size -n \
846 "${__var_height:+__height_menu_with_help_size}" \
847 "${__var_width:+__width_menu_with_help_size}" \
848 "$__title" "$__btitle" "$__prompt" "$__hline"
629
849
630 shift 4 # title/btitle/prompt/hline
631
632 # If there's no prompt, bump the max-rows by 1
633 [ "$prompt" ] || max_rows=$(( $max_rows + 1 ))
634
635 #
850 #
636 # The sum total between the longest tag-length and longest item-length
637 # should be used for the menu width (not to exceed terminal width).
851 # Always process the menu-item arguments to get the longest tag-length,
852 # longest item-length, longest help-length (help-length only considered
853 # if using Xdialog(1), as it places the help string in the widget) --
854 # all used to bump the width -- and the number of rows (used to bump
855 # the height).
638 #
856 #
639 # Also, calculate the number of rows (not to exceed terminal height).
640 #
641 # Also, calculate the longest help while we're here. This will be used
642 # to influence the width of the menu if (and only-if) using Xdialog(1).
643 #
644 local longest_tag=0 longest_item=0 longest_help=0
857 local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0
645 while [ $# -ge 3 ]; do
858 while [ $# -ge 3 ]; do
646 local tag="$1" item="$2" help="$3"
859 local __tag="$1" __item="$2" __help="$3"
647 shift 3 # tag/item/help
860 shift 3 # tag/item/help
648
649 [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag}
650 [ ${#item} -gt $longest_item ] && longest_item=${#item}
651 [ ${#help} -gt $longest_help ] && longest_help=${#help}
652 [ $rows -lt $max_rows ] && rows=$(( $rows + 1 ))
861 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
862 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
863 [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help}
864 __rows=$(( $__rows + 1 ))
653 done
654
865 done
866
655 # Update width
656 n=$(( $longest_tag + $longest_item + 10 ))
657 [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1)
658 if [ $n -gt $width -a $n -gt $min_width ]; then
659 if [ $n -lt $max_width ]; then
660 width=$n
867 # Adjust rows early (for up-coming height calculation)
868 if [ "$__var_height" -o "$__var_rows" ]; then
869 # Add a row for visual aid if using Xdialog(1)
870 [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
871 fi
872
873 # Adjust height if desired
874 if [ "$__var_height" ]; then
875 # Add rows to height
876 if [ "$USE_XDIALOG" ]; then
877 __height_menu_with_help_size=$((
878 $__height_menu_with_help_size + $__rows + 8 ))
661 else
879 else
662 width=$max_width
880 __height_menu_with_help_size=$((
881 $__height_menu_with_help_size + $__rows + 4 ))
663 fi
882 fi
883 setvar "$__var_height" $__height_menu_with_help_size
664 fi
665
884 fi
885
666 # Update width for help text if using Xdialog(1)
667 if [ "$USE_XDIALOG" ]; then
668 n=$(( $longest_help + 10 ))
669 n=$(( $n + $n / 6 )) # +16.6%
670 if [ $n -gt $width -a $n -gt $min_width ]; then
671 if [ $n -lt $max_width ]; then
672 width=$n
673 else
674 width=$max_width
675 fi
886 # Adjust width if desired
887 if [ "$__var_width" ]; then
888 # The sum total between the longest tag-length and the
889 # longest item-length should be used to bump menu width
890 local __n=$(( $__longest_tag + $__longest_item + 10 ))
891 [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
892 [ $__n -gt $__width_menu_with_help_size ] &&
893 __width_menu_with_help_size=$__n
894
895 # Update width for help text if using Xdialog(1)
896 if [ "$USE_XDIALOG" ]; then
897 __n=$(( $__longest_help + 10 ))
898 __n=$(( $__n + $__n / 6 )) # plus 16.6%
899 [ $__n -gt $__width_menu_with_help_size ] &&
900 __width_menu_with_help_size=$__n
676 fi
901 fi
677 fi
678
902
679 # Fix rows and set height
680 [ $rows -gt 0 ] || rows=1
681 if [ "$USE_XDIALOG" ]; then
682 height=$(( $rows + $box_height + 8 ))
683 else
684 height=$(( $rows + $box_height + 4 ))
903 setvar "$__var_width" $__width_menu_with_help_size
685 fi
904 fi
686 [ $height -le $max_height ] || height=$max_height
687
905
688 # Return all three
689 echo "$height $width $rows"
906 # Store adjusted rows if desired
907 [ "$__var_rows" ] && setvar "$__var_rows" $__rows
908
909 # Constrain height, width, and rows to sensible minimum/maximum values
910 # Return success if no-constrain, else return status from constrain
911 [ ! "$__constrain" ] || f_dialog_menu_constrain \
912 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
690}
691
913}
914
692# f_dialog_radiolist_size $title $backtitle $prompt $hline \
915# f_dialog_radiolist_size [-n] $var_height $var_width $var_rows \
916# $title $backtitle $prompt $hline \
693# $tag1 $item1 $status1 $tag2 $item2 $status2 ...
694#
695# Not all versions of dialog(1) perform auto-sizing of the width and height of
696# `--radiolist' boxes sensibly.
697#
917# $tag1 $item1 $status1 $tag2 $item2 $status2 ...
918#
919# Not all versions of dialog(1) perform auto-sizing of the width and height of
920# `--radiolist' boxes sensibly.
921#
698# This function helps solve this issue by taking as arguments (in order of
699# appearance) the title, backtitle, prompt, hline and list of tag/item/status
700# triplets, returning the optimal width and height for the radiolist (not
701# exceeding the actual terminal width or height).
922# This function helps solve this issue by taking three sets of sequential
923# arguments. The first set of arguments are the variable names to use when
924# storing the calculated height, width, and rows. The second set of arguments
925# are the title, backtitle, prompt, and hline. The [optional] third set of
926# arguments are the radio list itself (comprised of tag/item/status triplets).
927# The optimal height, width, and rows for the described widget (not exceeding
928# the actual terminal height or width) is stored in $var_height, $var_width,
929# and $var_rows (respectively).
702#
930#
703# Output is in the format of "height width rows".
931# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
932# and $var_rows) are not constrained to minimum/maximum values.
704#
705f_dialog_radiolist_size()
706{
933#
934f_dialog_radiolist_size()
935{
707 local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
708 local min_width min_rows max_size
936 local __constrain=1
937 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
938 local __var_height="$1" __var_width="$2" __var_rows="$3"
939 local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
940 shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
709
941
710 if [ "$USE_XDIALOG" ]; then
711 min_width=35
712 min_rows=1
713 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
714 else
715 min_width=24
716 min_rows=0
717 max_size=$( stty size 2> /dev/null ) # usually "24 80"
718 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
719 fi
942 # Return unless at least one size aspect has been requested
943 [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
944 return $FAILURE
720
945
721 local max_width="${max_size##*[$IFS]}"
722 local max_height="${max_size%%[$IFS]*}"
723 local box_size="$( f_dialog_infobox_size \
724 "$title" "$btitle" "$prompt" "$hline" )"
725 local box_height="${box_size%%[$IFS]*}"
726 local box_width="${box_size##*[$IFS]}"
727 local max_rows=$(( $max_height - 8 ))
728 local height width=$box_width rows=$min_rows
946 # Calculate height/width of infobox (adjusted/constrained below)
947 # NOTE: Function name appended to prevent __var_{height,width} values
948 # from becoming local (and thus preventing setvar from working).
949 local __height_rlist_size __width_rlist_size
950 f_dialog_infobox_size -n \
951 "${__var_height:+__height_rlist_size}" \
952 "${__var_width:+__width_rlist_size}" \
953 "$__title" "$__btitle" "$__prompt" "$__hline"
729
954
730 shift 4 # title/btitle/prompt/hline
731
732 #
955 #
733 # The sum total between the longest tag-length, longest item-length,
734 # and radio-button width should be used for the menu width (not to
735 # exceed terminal width).
956 # Always process the menu-item arguments to get the longest tag-length,
957 # longest item-length (both used to bump the width), and the number of
958 # rows (used to bump the height).
736 #
959 #
737 # Also, calculate the number of rows (not to exceed terminal height).
738 #
739 local longest_tag=0 longest_item=0
960 local __longest_tag=0 __longest_item=0 __rows=0
740 while [ $# -ge 3 ]; do
961 while [ $# -ge 3 ]; do
741 local tag="$1" item="$2"
962 local __tag="$1" __item="$2"
742 shift 3 # tag/item/status
963 shift 3 # tag/item/status
743
744 [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag}
745 [ ${#item} -gt $longest_item ] && longest_item=${#item}
746 [ $rows -lt $max_rows ] && rows=$(( $rows + 1 ))
964 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
965 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
966 __rows=$(( $__rows + 1 ))
747 done
748
967 done
968
749 # Update width
750 n=$(( $longest_tag + $longest_item + 13 ))
751 [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1)
752 if [ $n -gt $width -a $n -gt $min_width ]; then
753 if [ $n -lt $max_width ]; then
754 width=$n
969 # Adjust rows early (for up-coming height calculation)
970 if [ "$__var_height" -o "$__var_rows" ]; then
971 # Add a row for visual aid if using Xdialog(1)
972 [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
973 fi
974
975 # Adjust height if desired
976 if [ "$__var_height" ]; then
977 # Add rows to height
978 if [ "$USE_XDIALOG" ]; then
979 __height_rlist_size=$((
980 $__height_rlist_size + $__rows + 7 ))
755 else
981 else
756 width=$max_width
982 __height_rlist_size=$((
983 $__height_rlist_size + $__rows + 4 ))
757 fi
984 fi
985 setvar "$__var_height" $__height_rlist_size
758 fi
759
986 fi
987
760 # Fix rows and set height
761 [ $rows -gt 0 ] || rows=1
762 if [ "$USE_XDIALOG" ]; then
763 height=$(( $rows + $box_height + 7 ))
764 else
765 height=$(( $rows + $box_height + 4 ))
988 # Adjust width if desired
989 if [ "$__var_width" ]; then
990 # Sum total between longest tag-length, longest item-length,
991 # and radio-button width should be used to bump menu width
992 local __n=$(( $__longest_tag + $__longest_item + 13 ))
993 [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
994 [ $__n -gt $__width_rlist_size ] && __width_rlist_size=$__n
995
996 setvar "$__var_width" $__width_rlist_size
766 fi
997 fi
767 [ $height -le $max_height ] || height=$max_height
768
998
769 # Return all three
770 echo "$height $width $rows"
999 # Store adjusted rows if desired
1000 [ "$__var_rows" ] && setvar "$__var_rows" $__rows
1001
1002 # Constrain height, width, and rows to sensible minimum/maximum values
1003 # Return success if no-constrain, else return status from constrain
1004 [ ! "$__constrain" ] || f_dialog_menu_constrain \
1005 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
771}
772
1006}
1007
773# f_dialog_checklist_size $title $backtitle $prompt $hline \
1008# f_dialog_checklist_size [-n] $var_height $var_width $var_rows \
1009# $title $backtitle $prompt $hline \
774# $tag1 $item1 $status1 $tag2 $item2 $status2 ...
775#
776# Not all versions of dialog(1) perform auto-sizing of the width and height of
777# `--checklist' boxes sensibly.
778#
1010# $tag1 $item1 $status1 $tag2 $item2 $status2 ...
1011#
1012# Not all versions of dialog(1) perform auto-sizing of the width and height of
1013# `--checklist' boxes sensibly.
1014#
779# This function helps solve this issue by taking as arguments (in order of
780# appearance) the title, backtitle, prompt, hline and list of tag/item/status
781# triplets, returning the optimal width and height for the checklist (not
782# exceeding the actual terminal width or height).
1015# This function helps solve this issue by taking three sets of sequential
1016# arguments. The first set of arguments are the variable names to use when
1017# storing the calculated height, width, and rows. The second set of arguments
1018# are the title, backtitle, prompt, and hline. The [optional] third set of
1019# arguments are the check list itself (comprised of tag/item/status triplets).
1020# The optimal height, width, and rows for the described widget (not exceeding
1021# the actual terminal height or width) is stored in $var_height, $var_width,
1022# and $var_rows (respectively).
783#
1023#
784# Output is in the format of "height width rows".
1024# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
1025# and $var_rows) are not constrained to minimum/maximum values.
785#
786f_dialog_checklist_size()
787{
788 f_dialog_radiolist_size "$@"
789}
790
1026#
1027f_dialog_checklist_size()
1028{
1029 f_dialog_radiolist_size "$@"
1030}
1031
791# f_dialog_radiolist_with_help_size $title $backtitle $prompt $hline \
1032# f_dialog_radiolist_with_help_size [-n] $var_height $var_width $var_rows \
1033# $title $backtitle $prompt $hline \
792# $tag1 $item1 $status1 $help1 \
793# $tag2 $item2 $status2 $help2 ...
794#
795# Not all versions of dialog(1) perform auto-sizing of the width and height of
796# `--radiolist' boxes sensibly.
797#
1034# $tag1 $item1 $status1 $help1 \
1035# $tag2 $item2 $status2 $help2 ...
1036#
1037# Not all versions of dialog(1) perform auto-sizing of the width and height of
1038# `--radiolist' boxes sensibly.
1039#
798# This function helps solve this issue by taking as arguments (in order of
799# appearance) the title, backtitle, prompt, hline and list of
800# tag/item/status/help quads, returning the optimal width and height for the
801# radiolist (not exceeding the actual terminal width or height).
1040# This function helps solve this issue by taking three sets of sequential
1041# arguments. The first set of arguments are the variable names to use when
1042# storing the calculated height, width, and rows. The second set of arguments
1043# are the title, backtitle, prompt, and hline. The [optional] third set of
1044# arguments are the radio list itself (comprised of tag/item/status/help
1045# quadruplets). The optimal height, width, and rows for the described widget
1046# (not exceeding the actual terminal height or width) is stored in $var_height,
1047# $var_width, and $var_rows (respectively).
802#
1048#
803# Output is in the format of "height width rows".
1049# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
1050# and $var_rows) are not constrained to minimum/maximum values.
804#
805f_dialog_radiolist_with_help_size()
806{
1051#
1052f_dialog_radiolist_with_help_size()
1053{
807 local title="$1" btitle="$2" prompt="$3" hline="$4" n=0
808 local min_width min_rows max_size
1054 local __constrain=1
1055 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
1056 local __var_height="$1" __var_width="$2" __var_rows="$3"
1057 local __title="$4" __btitle="$5" __prompt="$6" __hline="$7"
1058 shift 7 # var_height/var_width/var_rows/title/btitle/prompt/hline
809
1059
810 if [ "$USE_XDIALOG" ]; then
811 min_width=35
812 min_rows=1
813 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
814 else
815 min_width=24
816 min_rows=0
817 max_size=$( stty size 2> /dev/null ) # usually "24 80"
818 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
819 fi
1060 # Return unless at least one size aspect has been requested
1061 [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
1062 return $FAILURE
820
1063
821 local max_width="${max_size##*[$IFS]}"
822 local max_height="${max_size%%[$IFS]*}"
823 local box_size="$( f_dialog_infobox_size \
824 "$title" "$btitle" "$prompt" "$hline" )"
825 local box_height="${box_size%%[$IFS]*}"
826 local box_width="${box_size##*[$IFS]}"
827 local max_rows=$(( $max_height - 8 ))
828 local height width=$box_width rows=$min_rows
1064 # Calculate height/width of infobox (adjusted/constrained below)
1065 # NOTE: Function name appended to prevent __var_{height,width} values
1066 # from becoming local (and thus preventing setvar from working).
1067 local __height_rlist_with_help_size __width_rlist_with_help_size
1068 f_dialog_infobox_size -n \
1069 "${__var_height:+__height_rlist_with_help_size}" \
1070 "${__var_width:+__width_rlist_with_help_size}" \
1071 "$__title" "$__btitle" "$__prompt" "$__hline"
829
1072
830 shift 4 # title/btitle/prompt/hline
831
832 #
1073 #
833 # The sum total between the longest tag-length, longest item-length,
834 # and radio-button width should be used for the menu width (not to
835 # exceed terminal width).
1074 # Always process the menu-item arguments to get the longest tag-length,
1075 # longest item-length, longest help-length (help-length only considered
1076 # if using Xdialog(1), as it places the help string in the widget) --
1077 # all used to bump the width -- and the number of rows (used to bump
1078 # the height).
836 #
1079 #
837 # Also, calculate the number of rows (not to exceed terminal height).
838 #
839 # Also, calculate the longest help while we're here. This will be used
840 # to influence the width of the menu if (and only-if) using Xdialog(1).
841 #
842 local longest_tag=0 longest_item=0 longest_help=0
1080 local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0
843 while [ $# -ge 4 ]; do
1081 while [ $# -ge 4 ]; do
844 local tag="$1" item="$2" status="$3" help="$4"
1082 local __tag="$1" __item="$2" __status="$3" __help="$4"
845 shift 4 # tag/item/status/help
1083 shift 4 # tag/item/status/help
846
847 [ ${#tag} -gt $longest_tag ] && longest_tag=${#tag}
848 [ ${#item} -gt $longest_item ] && longest_item=${#item}
849 [ ${#help} -gt $longest_help ] && longest_help=${#help}
850 [ $rows -lt $max_rows ] && rows=$(( $rows + 1 ))
1084 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
1085 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
1086 [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help}
1087 __rows=$(( $__rows + 1 ))
851 done
852
1088 done
1089
853 # Update width
854 n=$(( $longest_tag + $longest_item + 13 ))
855 [ "$USE_XDIALOG" ] && n=$(( $n + $n / 6 )) # Add 16.6% for Xdialog(1)
856 if [ $n -gt $width -a $n -gt $min_width ]; then
857 if [ $n -lt $max_width ]; then
858 width=$n
1090 # Adjust rows early (for up-coming height calculation)
1091 if [ "$__var_height" -o "$__var_rows" ]; then
1092 # Add a row for visual aid if using Xdialog(1)
1093 [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
1094 fi
1095
1096 # Adjust height if desired
1097 if [ "$__var_height" ]; then
1098 # Add rows to height
1099 if [ "$USE_XDIALOG" ]; then
1100 __height_rlist_with_help_size=$((
1101 $__height_rlist_with_help_size + $__rows + 7 ))
859 else
1102 else
860 width=$max_width
1103 __height_rlist_with_help_size=$((
1104 $__height_rlist_with_help_size + $__rows + 4 ))
861 fi
1105 fi
1106 setvar "$__var_height" $__height
862 fi
863
1107 fi
1108
864 # Update width for help text if using Xdialog(1)
865 if [ "$USE_XDIALOG" ]; then
866 n=$(( $longest_help + 10 ))
867 n=$(( $n + $n / 6 )) # +16.6%
868 if [ $n -gt $width -a $n -gt $min_width ]; then
869 if [ $n -lt $max_width ]; then
870 width=$n
871 else
872 width=$max_width
873 fi
1109 # Adjust width if desired
1110 if [ "$__var_width" ]; then
1111 # Sum total between longest tag-length, longest item-length,
1112 # and radio-button width should be used to bump menu width
1113 local __n=$(( $__longest_tag + $__longest_item + 13 ))
1114 [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
1115 [ $__n -gt $__width_rlist_with_help_size ] &&
1116 __width_rlist_with_help_size=$__n
1117
1118 # Update width for help text if using Xdialog(1)
1119 if [ "$USE_XDIALOG" ]; then
1120 __n=$(( $__longest_help + 10 ))
1121 __n=$(( $__n + $__n / 6 )) # plus 16.6%
1122 [ $__n -gt $__width_rlist_with_help_size ] &&
1123 __width_rlist_with_help_size=$__n
874 fi
1124 fi
875 fi
876
1125
877 # Fix rows and set height
878 [ $rows -gt 0 ] || rows=1
879 if [ "$USE_XDIALOG" ]; then
880 height=$(( $rows + $box_height + 7 ))
881 else
882 height=$(( $rows + $box_height + 4 ))
1126 setvar "$__var_width" $__width_rlist_with_help_size
883 fi
1127 fi
884 [ $height -le $max_height ] || height=$max_height
885
1128
886 # Return all three
887 echo "$height $width $rows"
1129 # Store adjusted rows if desired
1130 [ "$__var_rows" ] && setvar "$__var_rows" $__rows
1131
1132 # Constrain height, width, and rows to sensible minimum/maximum values
1133 # Return success if no-constrain, else return status from constrain
1134 [ ! "$__constrain" ] || f_dialog_menu_constrain \
1135 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
888}
889
1136}
1137
890# f_dialog_checklist_with_help_size $title $backtitle $prompt $hline \
1138# f_dialog_checklist_with_help_size [-n] $var_height $var_width $var_rows \
1139# $title $backtitle $prompt $hline \
891# $tag1 $item1 $status1 $help1 \
892# $tag2 $item2 $status2 $help2 ...
893#
894# Not all versions of dialog(1) perform auto-sizing of the width and height of
895# `--checklist' boxes sensibly.
896#
1140# $tag1 $item1 $status1 $help1 \
1141# $tag2 $item2 $status2 $help2 ...
1142#
1143# Not all versions of dialog(1) perform auto-sizing of the width and height of
1144# `--checklist' boxes sensibly.
1145#
897# This function helps solve this issue by taking as arguments (in order of
898# appearance) the title, backtitle, prompt, hline and list of
899# tag/item/status/help quads, returning the optimal width and height for the
900# checklist (not exceeding the actual terminal width or height).
1146# This function helps solve this issue by taking three sets of sequential
1147# arguments. The first set of arguments are the variable names to use when
1148# storing the calculated height, width, and rows. The second set of arguments
1149# are the title, backtitle, prompt, and hline. The [optional] third set of
1150# arguments are the check list itself (comprised of tag/item/status/help
1151# quadruplets). The optimal height, width, and rows for the described widget
1152# (not exceeding the actual terminal height or width) is stored in $var_height,
1153# $var_width, and $var_rows (respectively).
901#
1154#
902# Output is in the format of "height width rows".
1155# If the first argument is `-n', the calculated sizes ($var_height, $var_width,
1156# and $var_rows) are not constrained to minimum/maximum values.
903#
904f_dialog_checklist_with_help_size()
905{
906 f_dialog_radiolist_with_help_size "$@"
907}
908
1157#
1158f_dialog_checklist_with_help_size()
1159{
1160 f_dialog_radiolist_with_help_size "$@"
1161}
1162
909# f_dialog_calendar_size $title $backtitle $prompt [$hline]
1163# f_dialog_calendar_size [-n] $var_height $var_width \
1164# $title $backtitle $prompt [$hline]
910#
911# Not all versions of dialog(1) perform auto-sizing of the width and height of
912# `--calendar' boxes sensibly.
913#
1165#
1166# Not all versions of dialog(1) perform auto-sizing of the width and height of
1167# `--calendar' boxes sensibly.
1168#
914# This function helps solve this issue by taking as arguments (in order of
915# appearance) the title, backtitle, prompt, and [optionally] hline returning
916# the optimal width and height for the box (not exceeding the actual terminal
917# width and height).
1169# This function helps solve this issue by taking two sets of sequential
1170# arguments. The first set of arguments are the variable names to use when
1171# storing the calculated height and width. The second set of arguments are the
1172# title, backtitle, prompt, and [optionally] hline. The optimal height and
1173# width for the described widget (not exceeding the actual terminal height or
1174# width) is stored in $var_height and $var_width (respectively).
918#
1175#
1176# If the first argument is `-n', the calculated sizes ($var_height and
1177# $var_width) are not constrained to minimum/maximum values.
1178#
919# Newline character sequences (``\n'') in $prompt are expanded as-is done by
920# dialog(1).
921#
1179# Newline character sequences (``\n'') in $prompt are expanded as-is done by
1180# dialog(1).
1181#
922# Output is in the format of "height width".
923#
924f_dialog_calendar_size()
925{
1182f_dialog_calendar_size()
1183{
926 local title="$1" btitle="$2" prompt="$3" hline="$4" n
927 local size="$( f_dialog_infobox_size \
928 "$title" "$btitle" "$prompt" "$hline" )"
929 local height="${size%%[$IFS]*}"
930 local width="${size##*[$IFS]}"
1184 local __constrain=1
1185 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
1186 local __var_height="$1" __var_width="$2"
1187 local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
931
1188
932 local min_width min_height max_size
1189 # Return unless at least one size aspect has been requested
1190 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
1191
1192 #
1193 # Obtain/Adjust minimum and maximum thresholds
1194 # NOTE: Function name appended to prevent __var_{height,width} values
1195 # from becoming local (and thus preventing setvar from working).
1196 #
1197 local __max_height_cal_size __max_width_cal_size
1198 f_dialog_max_size __max_height_cal_size __max_width_cal_size
1199 __max_width_cal_size=$(( $__max_width_cal_size - 2 ))
1200 # the calendar box will refuse to display if too wide
1201 local __min_width
933 if [ "$USE_XDIALOG" ]; then
1202 if [ "$USE_XDIALOG" ]; then
934 min_height=15
935 min_width=55
936 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
1203 __min_width=55
937 else
1204 else
938 min_height=0
939 min_width=40
940 max_size=$( stty size 2> /dev/null ) # usually "24 80"
941 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
1205 __min_width=40
1206 __max_height_cal_size=$((
1207 $__max_height_cal_size - $DIALOG_CALENDAR_HEIGHT ))
1208 # When using dialog(1), we can't predict whether the user has
1209 # disabled shadow's in their `$HOME/.dialogrc' file, so we'll
1210 # subtract one for the potential shadow around the widget
1211 __max_height_cal_size=$(( $__max_height_cal_size - 1 ))
942 fi
1212 fi
943 local max_height="${max_size%%[$IFS]*}"
944 local max_width="${max_size##*[$IFS]}"
945
1213
946 #
947 # Enforce the minimum width for displaying the calendar
948 #
949 [ $width -ge $min_width ] || width=$min_width
1214 # Calculate height if desired
1215 if [ "$__var_height" ]; then
1216 local __height
1217 __height=$( echo "$__prompt" | f_number_of_lines )
950
1218
951 #
952 # When using dialog(1), the calendar box is unique from other dialog(1)
953 # boxes in-that the height passed should not accomodate the 15-lines
954 # required to display the calendar. This does not apply to Xdialog(1).
955 #
956 # When using Xdialog(1), the height must accomodate the 15-lines
957 # required to display the calendar.
958 #
959 # NOTE: Also under dialog(1), because we can't predict whether the user
960 # has disabled shadow's in their `$HOME/.dialogrc' file, we'll subtract
961 # 16 rather than 15. This does not apply to Xdialog(1).
962 #
963 max_height=$(( $max_height - 16 ))
964 height=$( echo "$prompt" | f_number_of_lines )
965 if [ "$USE_XDIALOG" ]; then
966 # Add height to accomodate for the embedded calendar widget
967 height=$(( $height + $min_height - 1 ))
1219 if [ "$USE_XDIALOG" ]; then
1220 # Add height to accomodate for embedded calendar widget
1221 __height=$(( $__height + $DIALOG_CALENDAR_HEIGHT - 1 ))
968
1222
969 # Also, bump height if backtitle is enabled
970 if [ "$btitle" ]; then
971 local n="$( echo "$btitle" | f_number_of_lines )"
972 height=$(( $height + $n + 2 ))
1223 # Also, bump height if backtitle is enabled
1224 if [ "$__btitle" ]; then
1225 local __n
1226 __n=$( echo "$__btitle" | f_number_of_lines )
1227 __height=$(( $__height + $__n + 2 ))
1228 fi
1229 else
1230 [ "$__prompt" ] && __height=$(( $__height + 1 ))
973 fi
1231 fi
974 else
975 [ "$prompt" ] && height=$(( $height + 1 ))
1232
1233 # Enforce maximum height, unless `-n' was passed
1234 [ "$__constrain" -a $__height -gt $__max_height_cal_size ] &&
1235 __height=$__max_height_cal_size
1236
1237 setvar "$__var_height" $__height
976 fi
1238 fi
977 [ $height -le $max_height ] || height=$max_height
978
1239
979 #
980 # The calendar box refuses to display if too large.
981 #
982 max_width=$(( $max_width - 2 ))
983 [ $width -le $max_width ] || width=$max_width
1240 # Calculate width if desired
1241 if [ "$__var_width" ]; then
1242 # NOTE: Function name appended to prevent __var_{height,width}
1243 # values from becoming local (and thus preventing setvar
1244 # from working).
1245 local __width_cal_size
1246 f_dialog_infobox_size -n "" __width_cal_size \
1247 "$__title" "$__btitle" "$__prompt" "$__hline"
984
1248
985 # Return both
986 echo "$height $width"
1249 # Enforce minimum/maximum width, unless `-n' was passed
1250 if [ "$__constrain" ]; then
1251 if [ $__width_cal_size -lt $__min_width ]; then
1252 __width_cal_size=$__min_width
1253 elif [ $__width_cal_size -gt $__max_width_cal_size ]
1254 then
1255 __width_cal_size=$__max_width_size
1256 fi
1257 fi
1258
1259 setvar "$__var_width" $__width_cal_size
1260 fi
1261
1262 return $SUCCESS
987}
988
1263}
1264
989# f_dialog_timebox_size $title $backtitle $prompt [$hline]
1265# f_dialog_timebox_size [-n] $var_height $var_width \
1266# $title $backtitle $prompt [$hline]
990#
991# Not all versions of dialog(1) perform auto-sizing of the width and height of
992# `--timebox' boxes sensibly.
993#
1267#
1268# Not all versions of dialog(1) perform auto-sizing of the width and height of
1269# `--timebox' boxes sensibly.
1270#
994# This function helps solve this issue by taking as arguments (in order of
995# appearance) the title, backtitle, prompt, and [optionally] hline returning
996# the optimal width and height for the box (not exceeding the actual terminal
997# width and height).
1271# This function helps solve this issue by taking two sets of sequential
1272# arguments. The first set of arguments are the variable names to use when
1273# storing the calculated height and width. The second set of arguments are the
1274# title, backtitle, prompt, and [optionally] hline. The optional height and
1275# width for the described widget (not exceeding the actual terminal height or
1276# width) is stored in $var_height and $var_width (respectively).
998#
1277#
1278# If the first argument is `-n', the calculated sizes ($var_height and
1279# $var_width) are not constrained to minimum/maximum values.
1280#
999# Newline character sequences (``\n'') in $prompt are expanded as-is done by
1000# dialog(1).
1001#
1281# Newline character sequences (``\n'') in $prompt are expanded as-is done by
1282# dialog(1).
1283#
1002# Output is in the format of "height width".
1003#
1004f_dialog_timebox_size()
1005{
1284f_dialog_timebox_size()
1285{
1006 local title="$1" btitle="$2" prompt="$3" hline="$4" n
1007 local size="$( f_dialog_infobox_size \
1008 "$title" "$btitle" "$prompt" "$hline" )"
1009 local height="${size%%[$IFS]*}"
1010 local width="${size##*[$IFS]}"
1286 local __constrain=1
1287 [ "$1" = "-n" ] && __constrain= && shift 1 # -n
1288 local __var_height="$1" __var_width="$2"
1289 local __title="$3" __btitle="$4" __prompt="$5" __hline="$6"
1011
1290
1012 local min_width min_height max_size
1013 if [ "$USE_XDIALOG" ]; then
1014 min_width=40
1015 max_size="$XDIALOG_MAXSIZE" # see CONFIGURATION
1016 else
1017 min_height=0
1018 min_width=20
1019 max_size=$( stty size 2> /dev/null ) # usually "24 80"
1020 : ${max_size:=$DEFAULT_TERMINAL_SIZE}
1021 fi
1022 local max_height="${max_size%%[$IFS]*}"
1023 local max_width="${max_size##*[$IFS]}"
1291 # Return unless at least one size aspect has been requested
1292 [ "$__var_height" -o "$__var_width" ] || return $FAILURE
1024
1025 #
1293
1294 #
1026 # Enforce the minimum width for displaying the timebox
1295 # Obtain/Adjust minimum and maximum thresholds
1296 # NOTE: Function name appended to prevent __var_{height,width} values
1297 # from becoming local (and thus preventing setvar from working).
1027 #
1298 #
1028 [ $width -ge $min_width ] || width=$min_width
1029
1030 #
1031 # When using dialog(1), the timebox box is unique from other dialog(1)
1032 # boxes in-that the height passed should not accomodate the 6-lines
1033 # required to display the timebox. This does not apply to Xdialog(1).
1034 #
1035 # When using Xdialog(1), the height seems to have no effect. All values
1036 # provide the same results.
1037 #
1038 # NOTE: Also under dialog(1), because we can't predict whether the user
1039 # has disabled shadow's in their `$HOME/.dialogrc' file, we'll subtract
1040 # 7 rather than 6. This does not apply to Xdialog(1).
1041 #
1299 local __max_height_tbox_size __max_width_tbox_size
1300 f_dialog_max_size __max_height_tbox_size __max_width_tbox_size
1301 __max_width_tbox_size=$(( $__max_width_tbox_size - 2 ))
1302 # the timebox widget refuses to display if too wide
1303 local __min_width
1042 if [ "$USE_XDIALOG" ]; then
1304 if [ "$USE_XDIALOG" ]; then
1043 height=0 # Autosize; all values produce same results
1305 __min_width=40
1044 else
1306 else
1045 max_height=$(( $max_height - 7 ))
1046 height=$( echo "$prompt" | f_number_of_lines )
1047 height=$(( $height + 1 ))
1048 [ $height -le $max_height ] || height=$max_height
1049 [ "$prompt" ] && height=$(( $height + 1 ))
1307 __min_width=20
1308 __max_height_tbox_size=$(( \
1309 $__max_height_tbox_size - $DIALOG_TIMEBOX_HEIGHT ))
1310 # When using dialog(1), we can't predict whether the user has
1311 # disabled shadow's in their `$HOME/.dialogrc' file, so we'll
1312 # subtract one for the potential shadow around the widget
1313 __max_height_tbox_size=$(( $__max_height_tbox_size - 1 ))
1050 fi
1051
1314 fi
1315
1052 #
1053 # The timebox box refuses to display if too large.
1054 #
1055 max_width=$(( $max_width - 2 ))
1056 [ $width -le $max_width ] || width=$max_width
1316 # Calculate height if desired
1317 if [ "$__var_height" -a "$USE_XDIALOG" ]; then
1318 # When using Xdialog(1), the height seems to have
1319 # no effect. All values provide the same results.
1320 setvar "$__var_height" 0 # autosize
1321 elif [ "$__var_height" ]; then
1322 local __height
1323 __height=$( echo "$__prompt" | f_number_of_lines )
1324 __height=$(( $__height ${__prompt:++1} + 1 ))
1057
1325
1058 # Return both
1059 echo "$height $width"
1326 # Enforce maximum height, unless `-n' was passed
1327 [ "$__constrain" -a $__height -gt $__max_height_tbox_size ] &&
1328 __height=$__max_height_tbox_size
1329
1330 setvar "$__var_height" $__height
1331 fi
1332
1333 # Calculate width if desired
1334 if [ "$__var_width" ]; then
1335 # NOTE: Function name appended to prevent __var_{height,width}
1336 # values from becoming local (and thus preventing setvar
1337 # from working).
1338 local __width_tbox_size
1339 f_dialog_infobox_size -n "" __width_tbox_size \
1340 "$__title" "$__btitle" "$__prompt" "$__hline"
1341
1342 # Enforce the minimum width for displaying the timebox
1343 if [ "$__constrain" ]; then
1344 if [ $__width_tbox_size -lt $__min_width ]; then
1345 __width_tbox_size=$__min_width
1346 elif [ $__width_tbox_size -ge $__max_width_tbox_size ]
1347 then
1348 __width_tbox_size=$__max_width_tbox_size
1349 fi
1350 fi
1351
1352 setvar "$__var_width" $__width_tbox_size
1353 fi
1354
1355 return $SUCCESS
1060}
1061
1062############################################################ CLEAR FUNCTIONS
1063
1064# f_dialog_clear
1065#
1066# Clears any/all previous dialog(1) displays.
1067#

--- 6 unchanged lines hidden (view full) ---

1074
1075# f_dialog_info $info_text ...
1076#
1077# Throw up a dialog(1) infobox. The infobox remains until another dialog is
1078# displayed or `dialog --clear' (or f_dialog_clear) is called.
1079#
1080f_dialog_info()
1081{
1356}
1357
1358############################################################ CLEAR FUNCTIONS
1359
1360# f_dialog_clear
1361#
1362# Clears any/all previous dialog(1) displays.
1363#

--- 6 unchanged lines hidden (view full) ---

1370
1371# f_dialog_info $info_text ...
1372#
1373# Throw up a dialog(1) infobox. The infobox remains until another dialog is
1374# displayed or `dialog --clear' (or f_dialog_clear) is called.
1375#
1376f_dialog_info()
1377{
1082 local info_text="$*"
1083 local size="$( f_dialog_infobox_size \
1084 "$DIALOG_TITLE" \
1085 "$DIALOG_BACKTITLE" \
1086 "$info_text" )"
1087
1088 eval $DIALOG \
1089 --title \"\$DIALOG_TITLE\" \
1090 --backtitle \"\$DIALOG_BACKTITLE\" \
1091 ${USE_XDIALOG:+--ignore-eof} \
1092 ${USE_XDIALOG:+--no-buttons} \
1093 --infobox \"\$info_text\" $size
1378 local info_text="$*" height width
1379 f_dialog_infobox_size height width \
1380 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text"
1381 $DIALOG \
1382 --title "$DIALOG_TITLE" \
1383 --backtitle "$DIALOG_BACKTITLE" \
1384 ${USE_XDIALOG:+--ignore-eof} \
1385 ${USE_XDIALOG:+--no-buttons} \
1386 --infobox "$info_text" $height $width
1094}
1095
1096# f_xdialog_info $info_text ...
1097#
1098# Throw up an Xdialog(1) infobox and do not dismiss it until stdin produces
1099# EOF. This implies that you must execute this either as an rvalue to a pipe,
1100# lvalue to indirection or in a sub-shell that provides data on stdin.
1101#
1102f_xdialog_info()
1103{
1387}
1388
1389# f_xdialog_info $info_text ...
1390#
1391# Throw up an Xdialog(1) infobox and do not dismiss it until stdin produces
1392# EOF. This implies that you must execute this either as an rvalue to a pipe,
1393# lvalue to indirection or in a sub-shell that provides data on stdin.
1394#
1395f_xdialog_info()
1396{
1104 local info_text="$*"
1105 local size="$( f_dialog_infobox_size \
1106 "$DIALOG_TITLE" \
1107 "$DIALOG_BACKTITLE" \
1108 "$info_text" )"
1109
1110 eval $DIALOG \
1111 --title \"\$DIALOG_TITLE\" \
1112 --backtitle \"\$DIALOG_BACKTITLE\" \
1113 --no-close --no-buttons \
1114 --infobox \"\$info_text\" $size \
1397 local info_text="$*" height width
1398 f_dialog_infobox_size height width \
1399 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$info_text"
1400 $DIALOG \
1401 --title "$DIALOG_TITLE" \
1402 --backtitle "$DIALOG_BACKTITLE" \
1403 --no-close --no-buttons \
1404 --infobox "$info_text" $height $width \
1115 -1 # timeout of -1 means abort when EOF on stdin
1116}
1117
1118############################################################ MSGBOX FUNCTIONS
1119
1120# f_dialog_msgbox $msg_text ...
1121#
1122# Throw up a dialog(1) msgbox. The msgbox remains until the user presses ENTER
1123# or ESC, acknowledging the modal dialog.
1124#
1125# If the user presses ENTER, the exit status is zero (success), otherwise if
1126# the user presses ESC the exit status is 255.
1127#
1128f_dialog_msgbox()
1129{
1405 -1 # timeout of -1 means abort when EOF on stdin
1406}
1407
1408############################################################ MSGBOX FUNCTIONS
1409
1410# f_dialog_msgbox $msg_text ...
1411#
1412# Throw up a dialog(1) msgbox. The msgbox remains until the user presses ENTER
1413# or ESC, acknowledging the modal dialog.
1414#
1415# If the user presses ENTER, the exit status is zero (success), otherwise if
1416# the user presses ESC the exit status is 255.
1417#
1418f_dialog_msgbox()
1419{
1130 local msg_text="$*"
1131 local size="$( f_dialog_buttonbox_size \
1132 "$DIALOG_TITLE" \
1133 "$DIALOG_BACKTITLE" \
1134 "$msg_text" )"
1135
1136 eval $DIALOG \
1137 --title \"\$DIALOG_TITLE\" \
1138 --backtitle \"\$DIALOG_BACKTITLE\" \
1139 --ok-label \"\$msg_ok\" \
1140 --msgbox \"\$msg_text\" $size
1420 local msg_text="$*" height width
1421 f_dialog_buttonbox_size height width \
1422 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text"
1423 $DIALOG \
1424 --title "$DIALOG_TITLE" \
1425 --backtitle "$DIALOG_BACKTITLE" \
1426 --ok-label "$msg_ok" \
1427 --msgbox "$msg_text" $height $width
1141}
1142
1143############################################################ TEXTBOX FUNCTIONS
1144
1145# f_dialog_textbox $file
1146#
1147# Display the contents of $file (or an error if $file does not exist, etc.) in
1148# a dialog(1) textbox (which has a scrollable region for the text). The textbox
1149# remains until the user presses ENTER or ESC, acknowledging the modal dialog.
1150#
1151# If the user presses ENTER, the exit status is zero (success), otherwise if
1152# the user presses ESC the exit status is 255.
1153#
1154f_dialog_textbox()
1155{
1156 local file="$1"
1428}
1429
1430############################################################ TEXTBOX FUNCTIONS
1431
1432# f_dialog_textbox $file
1433#
1434# Display the contents of $file (or an error if $file does not exist, etc.) in
1435# a dialog(1) textbox (which has a scrollable region for the text). The textbox
1436# remains until the user presses ENTER or ESC, acknowledging the modal dialog.
1437#
1438# If the user presses ENTER, the exit status is zero (success), otherwise if
1439# the user presses ESC the exit status is 255.
1440#
1441f_dialog_textbox()
1442{
1443 local file="$1"
1157 local contents retval size
1444 local contents height width retval
1158
1159 contents=$( cat "$file" 2>&1 )
1160 retval=$?
1161
1445
1446 contents=$( cat "$file" 2>&1 )
1447 retval=$?
1448
1162 size=$( f_dialog_buttonbox_size \
1163 "$DIALOG_TITLE" \
1164 "$DIALOG_BACKTITLE" \
1165 "$contents" )
1449 f_dialog_buttonbox_size height width \
1450 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$contents"
1166
1167 if [ $retval -eq $SUCCESS ]; then
1451
1452 if [ $retval -eq $SUCCESS ]; then
1168 eval $DIALOG \
1169 --title \"\$DIALOG_TITLE\" \
1170 --backtitle \"\$DIALOG_BACKTITLE\" \
1171 --exit-label \"\$msg_ok\" \
1172 --no-cancel \
1173 --textbox \"\$file\" $size
1453 $DIALOG \
1454 --title "$DIALOG_TITLE" \
1455 --backtitle "$DIALOG_BACKTITLE" \
1456 --exit-label "$msg_ok" \
1457 --no-cancel \
1458 --textbox "$file" $height $width
1174 else
1459 else
1175 eval $DIALOG \
1176 --title \"\$DIALOG_TITLE\" \
1177 --backtitle \"\$DIALOG_BACKTITLE\" \
1178 --ok-label \"\$msg_ok\" \
1179 --msgbox \"\$contents\" $size
1460 $DIALOG \
1461 --title "$DIALOG_TITLE" \
1462 --backtitle "$DIALOG_BACKTITLE" \
1463 --ok-label "$msg_ok" \
1464 --msgbox "$contents" $height $width
1180 fi
1181}
1182
1183############################################################ YESNO FUNCTIONS
1184
1185# f_dialog_yesno $msg_text ...
1186#
1187# Display a dialog(1) Yes/No prompt to allow the user to make some decision.
1188# The yesno prompt remains until the user presses ENTER or ESC, acknowledging
1189# the modal dialog.
1190#
1191# If the user chooses YES the exit status is zero, or chooses NO the exit
1192# status is one, or presses ESC the exit status is 255.
1193#
1194f_dialog_yesno()
1195{
1465 fi
1466}
1467
1468############################################################ YESNO FUNCTIONS
1469
1470# f_dialog_yesno $msg_text ...
1471#
1472# Display a dialog(1) Yes/No prompt to allow the user to make some decision.
1473# The yesno prompt remains until the user presses ENTER or ESC, acknowledging
1474# the modal dialog.
1475#
1476# If the user chooses YES the exit status is zero, or chooses NO the exit
1477# status is one, or presses ESC the exit status is 255.
1478#
1479f_dialog_yesno()
1480{
1196 local msg_text="$*"
1481 local msg_text="$*" height width
1197 local hline="$hline_arrows_tab_enter"
1198
1199 f_interactive || return 0 # If non-interactive, return YES all the time
1200
1482 local hline="$hline_arrows_tab_enter"
1483
1484 f_interactive || return 0 # If non-interactive, return YES all the time
1485
1201 local size="$( f_dialog_buttonbox_size \
1202 "$DIALOG_TITLE" \
1203 "$DIALOG_BACKTITLE" \
1204 "$msg_text" \
1205 "$hline" )"
1486 f_dialog_buttonbox_size height width \
1487 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline"
1206
1207 if [ "$USE_XDIALOG" ]; then
1488
1489 if [ "$USE_XDIALOG" ]; then
1208 eval $DIALOG \
1209 --title \"\$DIALOG_TITLE\" \
1210 --backtitle \"\$DIALOG_BACKTITLE\" \
1211 --hline \"\$hline\" \
1212 --ok-label \"\$msg_yes\" \
1213 --cancel-label \"\$msg_no\" \
1214 --yesno \"\$msg_text\" $size
1490 $DIALOG \
1491 --title "$DIALOG_TITLE" \
1492 --backtitle "$DIALOG_BACKTITLE" \
1493 --hline "$hline" \
1494 --ok-label "$msg_yes" \
1495 --cancel-label "$msg_no" \
1496 --yesno "$msg_text" $height $width
1215 else
1497 else
1216 eval $DIALOG \
1217 --title \"\$DIALOG_TITLE\" \
1218 --backtitle \"\$DIALOG_BACKTITLE\" \
1219 --hline \"\$hline\" \
1220 --yes-label \"\$msg_yes\" \
1221 --no-label \"\$msg_no\" \
1222 --yesno \"\$msg_text\" $size
1498 $DIALOG \
1499 --title "$DIALOG_TITLE" \
1500 --backtitle "$DIALOG_BACKTITLE" \
1501 --hline "$hline" \
1502 --yes-label "$msg_yes" \
1503 --no-label "$msg_no" \
1504 --yesno "$msg_text" $height $width
1223 fi
1224}
1225
1226# f_dialog_noyes $msg_text ...
1227#
1228# Display a dialog(1) No/Yes prompt to allow the user to make some decision.
1229# The noyes prompt remains until the user presses ENTER or ESC, acknowledging
1230# the modal dialog.
1231#
1232# If the user chooses YES the exit status is zero, or chooses NO the exit
1233# status is one, or presses ESC the exit status is 255.
1234#
1235# NOTE: This is just like the f_dialog_yesno function except "No" is default.
1236#
1237f_dialog_noyes()
1238{
1505 fi
1506}
1507
1508# f_dialog_noyes $msg_text ...
1509#
1510# Display a dialog(1) No/Yes prompt to allow the user to make some decision.
1511# The noyes prompt remains until the user presses ENTER or ESC, acknowledging
1512# the modal dialog.
1513#
1514# If the user chooses YES the exit status is zero, or chooses NO the exit
1515# status is one, or presses ESC the exit status is 255.
1516#
1517# NOTE: This is just like the f_dialog_yesno function except "No" is default.
1518#
1519f_dialog_noyes()
1520{
1239 local msg_text="$*"
1521 local msg_text="$*" height width
1240 local hline="$hline_arrows_tab_enter"
1241
1242 f_interactive || return 1 # If non-interactive, return NO all the time
1243
1522 local hline="$hline_arrows_tab_enter"
1523
1524 f_interactive || return 1 # If non-interactive, return NO all the time
1525
1244 local size="$( f_dialog_buttonbox_size \
1245 "$DIALOG_TITLE" \
1246 "$DIALOG_BACKTITLE" \
1247 "$msg_text" \
1248 "$hline" )"
1526 f_dialog_buttonbox_size height width \
1527 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_text" "$hline"
1249
1250 if [ "$USE_XDIALOG" ]; then
1528
1529 if [ "$USE_XDIALOG" ]; then
1251 eval $DIALOG \
1252 --title \"\$DIALOG_TITLE\" \
1253 --backtitle \"\$DIALOG_BACKTITLE\" \
1254 --hline \"\$hline\" \
1255 --default-no \
1256 --ok-label \"\$msg_yes\" \
1257 --cancel-label \"\$msg_no\" \
1258 --yesno \"\$msg_text\" $size
1530 $DIALOG \
1531 --title "$DIALOG_TITLE" \
1532 --backtitle "$DIALOG_BACKTITLE" \
1533 --hline "$hline" \
1534 --default-no \
1535 --ok-label "$msg_yes" \
1536 --cancel-label "$msg_no" \
1537 --yesno "$msg_text" $height $width
1259 else
1538 else
1260 eval $DIALOG \
1261 --title \"\$DIALOG_TITLE\" \
1262 --backtitle \"\$DIALOG_BACKTITLE\" \
1263 --hline \"\$hline\" \
1264 --defaultno \
1265 --yes-label \"\$msg_yes\" \
1266 --no-label \"\$msg_no\" \
1267 --yesno \"\$msg_text\" $size
1539 $DIALOG \
1540 --title "$DIALOG_TITLE" \
1541 --backtitle "$DIALOG_BACKTITLE" \
1542 --hline "$hline" \
1543 --defaultno \
1544 --yes-label "$msg_yes" \
1545 --no-label "$msg_no" \
1546 --yesno "$msg_text" $height $width
1268 fi
1269}
1270
1271############################################################ INPUT FUNCTIONS
1272
1273# f_dialog_inputstr
1274#
1275# Obtain the inputstr entered by the user from the most recently displayed

--- 31 unchanged lines hidden (view full) ---

1307# exit status is instead 1.
1308#
1309# NOTE: The hline should correspond to the type of data you want from the user.
1310# NOTE: Should not be used to edit multiline values.
1311#
1312f_dialog_input()
1313{
1314 local prompt="$1" init="$2" hline="$3"
1547 fi
1548}
1549
1550############################################################ INPUT FUNCTIONS
1551
1552# f_dialog_inputstr
1553#
1554# Obtain the inputstr entered by the user from the most recently displayed

--- 31 unchanged lines hidden (view full) ---

1586# exit status is instead 1.
1587#
1588# NOTE: The hline should correspond to the type of data you want from the user.
1589# NOTE: Should not be used to edit multiline values.
1590#
1591f_dialog_input()
1592{
1593 local prompt="$1" init="$2" hline="$3"
1315 local size="$( f_dialog_inputbox_size \
1316 "$DIALOG_TITLE" \
1317 "$DIALOG_BACKTITLE" \
1318 "$prompt" \
1319 "$init" \
1320 "$hline" )"
1594 local height width
1595 f_dialog_inputbox_size height width \
1596 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" \
1597 "$prompt" "$init" "$hline"
1321
1322 local opterm="--"
1323 [ "$USE_XDIALOG" ] && opterm=
1324
1325 local dialog_input
1326 dialog_input=$(
1598
1599 local opterm="--"
1600 [ "$USE_XDIALOG" ] && opterm=
1601
1602 local dialog_input
1603 dialog_input=$(
1327 eval $DIALOG \
1328 --title \"\$DIALOG_TITLE\" \
1329 --backtitle \"\$DIALOG_BACKTITLE\" \
1330 --hline \"\$hline\" \
1331 --ok-label \"\$msg_ok\" \
1332 --cancel-label \"\$msg_cancel\" \
1333 --inputbox \"\$prompt\" $size \
1334 $opterm \"\$init\" \
1604 $DIALOG \
1605 --title "$DIALOG_TITLE" \
1606 --backtitle "$DIALOG_BACKTITLE" \
1607 --hline "$hline" \
1608 --ok-label "$msg_ok" \
1609 --cancel-label "$msg_cancel" \
1610 --inputbox "$prompt" \
1611 $height $width \
1612 $opterm "$init" \
1335 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
1336 )
1337 local retval=$?
1338
1339 setvar DIALOG_INPUTBOX_$$ "$dialog_input"
1340 f_dialog_inputstr
1341
1342 return $retval

--- 261 unchanged lines hidden (view full) ---

1604 # Probe Xdialog(1) for maximum height/width constraints, or die
1605 # gracefully
1606 #
1607 if [ "$USE_XDIALOG" ]; then
1608 if ! maxsize=$( LANG= LC_ALL= $DIALOG --print-maxsize 2>&1 )
1609 then
1610 # Xdialog(1) failed, fall back to dialog(1)
1611 unset USE_XDIALOG
1613 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
1614 )
1615 local retval=$?
1616
1617 setvar DIALOG_INPUTBOX_$$ "$dialog_input"
1618 f_dialog_inputstr
1619
1620 return $retval

--- 261 unchanged lines hidden (view full) ---

1882 # Probe Xdialog(1) for maximum height/width constraints, or die
1883 # gracefully
1884 #
1885 if [ "$USE_XDIALOG" ]; then
1886 if ! maxsize=$( LANG= LC_ALL= $DIALOG --print-maxsize 2>&1 )
1887 then
1888 # Xdialog(1) failed, fall back to dialog(1)
1889 unset USE_XDIALOG
1612 size=$( f_dialog_buttonbox_size "$DIALOG_TITLE" \
1613 "$DIALOG_BACKTITLE" \
1614 "$maxsize" "" )
1615 eval dialog \
1616 --title \"\$DIALOG_TITLE\" \
1617 --backtitle \"\$DIALOG_BACKTITLE\" \
1618 --ok-label \"\$msg_ok\" \
1619 --msgbox \"\$maxsize\" $size
1890
1891 # Display the error message produced by Xdialog(1)
1892 local height width
1893 f_dialog_buttonbox_size height width \
1894 "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$maxsize"
1895 dialog \
1896 --title "$DIALOG_TITLE" \
1897 --backtitle "$DIALOG_BACKTITLE" \
1898 --ok-label "$msg_ok" \
1899 --msgbox "$maxsize" $height $width
1620 exit $FAILURE
1621 fi
1622
1623 XDIALOG_MAXSIZE=$(
1624 set -- ${maxsize##*:}
1625
1626 height=${1%,}
1627 width=$2

--- 37 unchanged lines hidden ---
1900 exit $FAILURE
1901 fi
1902
1903 XDIALOG_MAXSIZE=$(
1904 set -- ${maxsize##*:}
1905
1906 height=${1%,}
1907 width=$2

--- 37 unchanged lines hidden ---