boxlib is a simple, pure Bash library that provides a collection of APIs for creating TUI (terminal user interface)
applications, such as installers, rescue disks or interactive scripts. It supports both Whiptail and Dialog as backends for rendering the boxes on the screen.

Features & Advantages
-
🧠 Simple, Practical & Highly Intuitive
As a library, boxlib lets the developers to write less boilerplate code and more business logic.
Moreover, it also removes needless complexity, and bridges the gap between Dialog and Whiptail.
-
🌟 Feature Emulation: Bring Dialog’s Exclusive Features to Whiptail
Whiptail is designed to be drop-in compatible with Dialog, but it lacks several features
compared to Dialog (e.g., tailbox, timebox, calendarbox, etc.).
boxlib “backports” all of the missing boxes into Whiptail by emulating them using
existing functionality.
For example, the calendar box is emulated using an input field with
validation. The file/directory selector box and form are emulated using
the menu box.
-
🧩 Renderer Compatibility
boxlib aims to be fully compatibile with both Whiptail & Dialog, and offer a consistent and
unified interface with no need to adapt code per backend.
-
📢 Communication Between Boxes
In a multi-level hierarchy, the boxes may need to communicate
with each other.
For that, the library puts at your disposal a built-in communication mechanism, which offers
-
Basic Callback Support
You can attach [callback][box-common-options-callback]s (functions, scripts or executables)
to individual boxes and capture their result and the status code in a completely isolated way.
There are various options to configure the behavior of the callback system, such as
[abortOnRendererFailure][box-common-options-abort_on_renderer_failure] to fail-fast the
whole callback chain and cause the app to exit.
-
Callback Status Code Propagation Support
Sometimes, you want to decide in the parent box (e.g., main menu) the specific behavior
(e.g., remove entry from menu) depending on state of the child box. For that, you’ll have
the status code propagation mechanism that allows you to pass the exit code from the child
box through the entire callback chain, up to the parent box.
-
Callback Environment Propagation Support
Since Bash’s scoping mechanism makes local variables behave mostly like actual global
variables, it may cause variable pollution and collisions. To address that, boxlib runs
all the callbacks in a sandboxed environment (sub-shell). Unfortunately, variable changes
won’t be visible in the parent. For that, you’ll have the callback environment
propagation mechanism, that migrates the exported variables to the parent’s environment
variable space, ensuring the communication between the boxes is always isolated.
-
🧭 Breadcrumb Navigation
The library implements a breadcrumb stack displayed at the top of the screen to help maintain
context when exploring multi-level box hierarchies.
-
⚙️ Global Configuration Per Session
The library is globally configurable (e.g., select renderer) using config component.
It’s also possible to set common box options (e.g., maximize all boxes) once at startup or
elsewhere during execution.
-
🎯 Smart Renderer Selection
The library will automatically decide which utility will be used to render boxes when it’s
imported (sourced) into your project. Dialog is preferred, if available in the system,
otherwise, it falls back to Whiptail. When neither is found, a panic error is thrown.
-
🖥️ Cross-platform Compatibility
The library attempts to be POSIX-compliant in order to offer the same experience across Linux,
*BSD and other systems. Tested on the following systems upon release:
- Ubuntu 22.04
- FreeBSD 14.2
- macOS Sonoma (version 14)
-
✨ …and many more!
Underneath, the library already includes many things what you’ll have to write anyway, so you can
focus on your app’s logic.
- Want to easily loop a box (e.g. a menu) until user exits? Just set [
loop=true][box-common-options-loop] option!
- Need the box size to be 50% of the terminal size? Set [
width=50%][box-common-options-width]
and [height=50%][box-common-options-height] options to dynamically scale with the terminal!
Demo
Try the demo/main.sh script to explore all available box/widget types.
You can also run each example individually from the demo/ directory if you want.
[!TIP]
Since Dialog is the preferred renderer, you can force Whiptail by setting the
[BOXLIB_USE_WHIPTAIL=1][global-vars-use-whiptail] environment variable:
BOXLIB_USE_WHIPTAIL=1 ./demo/main.sh 1 # or BOXLIB_USE_WHIPTAIL=1 bash demo/menu.sh
Example
Example of a menu box created with Whiptail and with boxlib.
| Whiptail-only | the equivalent with boxlib |
|
declare -a options=(
'1) Option 1' 'Summary 1'
'2) Option 2' ''
)
# conditionally hide option
if false; then
options+=('3) Option 3' 'Summary 3')
fi
while true; do
if ! result="$(whiptail \
--backtitle 'My Project' \
--title 'Main menu' \
--cancel-button 'Exit' \
--menu 'Choose an option' \
0 0 0 \
"${options[@]}" \
3>&1 1>&2 2>&3)"; then
break
fi
# Get rid of the enumeration part
option="${result#* }"
case "$result" in
1*)
myCallBack1
;;
2*)
source path/to/callback.sh "$option"
;;
3*)
myCallBack3
;;
*)
echo "Unhandled option: $option"
exit 1
;;
esac
done
|
source boxlib/core.sh
config headerTitle='My Project'
function menu_handler() {
local option="$1"
case "$option" in
'Option 1') myCallBack1;;
'Option 3') myCallBack3;;
esac
}
menu \
title='Main menu' \
text='Choose an option' \
cancelLabel='Exit' \
callback='menu_handler()' \
loop='true' \
prefix='num'
menuEntry \
title='Option 1' \
summary='Summary 1'
menuEntry \
title='Option 2' \
callback='path/to/callback.sh'
# conditionally hide option
if false; then
menuEntry \
title='Option 3' \
summary='Summary 3'
fi
menuDraw
|
You might wonder why the above example is Whiptail-only, as the same arguments can be used in Dialog to create a menu box. It’s true, but overall behavior will be slightly different. For example, when running with Whiptail, the terminal will be cleared automatically after exiting. Dialog, in turn, requires the --keep-tite argument to accomplish this. The boxlib will handle this and bridge many other small gaps between the two for you.
|
See more demos examples here.
Requirements
[!NOTE]
Both Whiptail and Dialog utilites are pre-installed on most modern systems. Whiptail is available by
default on Debian-based systems as part of the Newt
package, while *BSD ones provide Dialog or BSDDialog.
boxlib automatically detects and selects the appropriate backend when it’s imported (sourced).
- Bash v4.3 (Bash v4.4 recommended)
[!TIP]
While Bash v4.3 is fully supported, certain distro-specific builds and patch versions (Bash
v4.3.48 is the latest) may contain known bugs, that were fixed only in Bash v4.4.
Installation Instructions
-
Create a Git project
git init
-
Clone this repo into your project using one of the following ways:
Submodule/Subtree Cheatsheet
-
Create an entrypoint script file (will name it main.sh) in the project root directory & make it executable
touch main.sh && chmod +x $_
3.1. Import (source) the library core component at the very top of the entrypoint (main.sh) file
#!/usr/bin/env bash
source boxlib/core.sh
-
That’s it!
See the Example section on how to create your first main menu box.
For the components provided by the library, refer to the Components section.
Getting updates
To get the latest library updates, run the appropriate command in the project root directory:
-
If boxlib is added as submodule
git submodule update --remote --recursive --force boxlib
This command selectively updates only the submodule directory where the library is located.
You may want to commit the changes.
-
If boxlib added as subtree
git subtree pull --prefix=boxlib https://github.com/iusmac/boxlib.git master --squash
Submodule/Subtree Cheatsheet
Components
Below is the list of core components that will be available to you anywhere after the library has been imported (sourced).
You can also get the usage screen by invoking the command with help argument.
Config
Component to globally configure the library and set common box options.
- Config changes affect only future boxes.
- Box-specific or Whiptail/Dialog-specific options take precedence over options set via config.
List of commands:
config <options> [<box-options>]
Example usage:
# Set a custom breadcrumb delimiter and maximize all boxes.
# Also pass the --fb option to all boxes for full buttons
config \
breadcrumbsDelim=' › ' \
width='max' \
height='max' \
\( --fb \)
text text='This text box should be fully maximized'
text text='This text box should be auto-sized to fit the contents' width='auto' height='auto'
| Option |
Default |
Description |
headerTitle=
headerTitle+= |
"" |
The string to be displayed on the backdrop, at the top of the screen alongside the breadcrumbs. |
rendererPath= |
dialog |
[#][config-options-renderer_path] The absolute path to Dialog or Whiptail binary that will render the boxes. |
rendererName= |
dialog |
[#][config-options-renderer_name] The renderer name when renderer binary is specified. Possible values: dialog, whiptail. |
breadcrumbsDelim= |
> |
[#][config-options-breadcrumbs_delim] Set the breadcrumb delimiter string. Can by any length. |
debug=
debug |
/dev/null |
[#][config-options-debug] The file name where to write debug logs. This option takes precedence over the [BOXLIB_DEBUG][global-vars-debug] environment variable. When no value is provided, will exit with 0 or 1 indicating the enabled debug state.| Possible values | |
|---|
stdout | prints debug to the standard output | stderr | prints debug to the standard error | <filename> | writes debug to the given filename. |
|
isDialogRenderer |
|
[#][config-options-is_dialog_renderer] Check whether Dialog is the default renderer. Will print true or false and also exit with 0 or 1. |
reset |
|
[#][config-options-reset] Reset the configuration to defaults. |
help |
|
[#][config-options-help] Print the usage screen and exit. |
Box
Below is the list of box components that allow you to easily launch any Dialog/Whiptail box.
Each box can be configured using two different types of the arguments:
- library-specific options
- Whiptail/Dialog-specific options
The Whiptail/Dialog-specific options use the special [round bracket syntax][box-common-options-round-bracket-syntax] to pass options to the box. For example:
# Create an input box with a custom backtitle in lieu of header title & breadcrumb stack
input \
text='My input' \
\( --backtitle 'My custom backtitle' \)
# The equivalent with Dialog
dialog \
--backtitle 'My custom backtitle' \
--inputbox 'My input' 0 0
See also the Communication between boxes section on how to interact
with boxes and different ways to capture the result.
Common options
Each box may have its own specific options, but all boxes share the following common options:
| Option |
Default |
Description |
title=
title+= |
"" |
[#][box-common-options-title] The string that is displayed at the top of the box. Same as using Whiptail/Dialog’s --title option. |
text=
text+= |
"" |
[#][box-common-options-text] The string that is displayed inside the box. |
width= |
auto also requires height='auto' |
[#][box-common-options-width] The width of the box. Use auto or 0 to auto-size to fit the contents. Use max or -1 to maximize. Can be denoted using percent sign, (e.g., 50%), to adjust dynamically based on the tput cols command. |
height= |
auto also requires width='auto' |
[#][box-common-options-height] The height of the box. Use auto or 0 to auto-size to fit the contents. Use max or -1 to maximize. Can be denoted using percent sign, (e.g., 50%), to adjust dynamically based on the tput lines command. |
callback= |
|
[#][box-common-options-callback] The callback to receive the result(s) from the box. The callback will be:- invoked as a local function if it ends with
() - executed if it’s a file with the “execute” bit set
- sourced as a shell script file if it’s none of the above
In all cases, the callback should expect the result(s) as input parameters. When executed, the $? variable will contain the exit code from the renderer (Whiptail/Dialog).
NOTE:- The callback execution will be sandboxed, i.e., it will run in a sub-shell. This ensures the interaction is isolated.
- If the callback is a relative path to a file, then it will be searched starting from the working directory.
Also, the CWD will be changed to where the callback file is located before executing/sourcing it. To disable, set [changeToCallbackDir=false][box-common-options-change_to_callback_dir].
|
See All Options
| Option |
Default |
Description |
changeToCallbackDir= |
true |
[#][box-common-options-change_to_callback_dir] Whether to change the working directory to where the callback script/executable is located before executing/sourcing it. Possible values: true (or 1), false (or 0). |
abortOnCallbackFailure= |
false |
[#][box-common-options-abort_on_callback_failure] Whether to abort immediately when the callback exits with a non-zero code. This will cause the whole callback chain to be interrupted including this box. For example, if applied on the root box that is the entry point for all boxes (e.g., main menu), then the app will exit. Useful for debugging/development purposes or in combination with [loop=true][box-common-options-loop] option. Possible values: true (or 1), false (or 0). |
propagateCallbackExitCode= |
true |
[#][box-common-options-propagate_callback_exit_code] Whether to propagate the callback exit code instead of the renderer exit code when the box exits. Also, if no callback is provided, the renderer exit code will be used. Possible values: true (or 1), false (or 0). |
alwaysInvokeCallback= |
false |
[#][box-common-options-always_invoke_callback] Whether to invoke the callback even if the renderer (Whiptail/Dialog) exited with a non-zero code. A non-zero code means the user pressed ESC key or Cancel button or answered No. When set to true, the callback will always be invoked, and the $? variable variable will contain the exit code from the renderer. Possible values: true (or 1), false (or 0). |
printResult= |
false |
[#][box-common-options-print_result] Whether to print the result(s) to stdout, each on a new line, after the box exits. Possible values: true (or 1), false (or 0). |
abortOnRendererFailure= |
false |
[#][box-common-options-abort_on_renderer_failure] Whether to abort immediately when the box renderer (Whiptail/Dialog) exits with a non-zero code AND with an error message printed to the standard error. No callbacks will be invoked even if [alwaysInvokeCallback][box-common-options-always_invoke_callback] option has been used. Useful to fail-fast on renderer errors, such as invalid options. You may also want to combine it with the [abortOnCallbackFailure=true][box-common-options-abort_on_callback_failure] option, to cause the whole callback chain, if any, to be interrupted. Possible values: true (or 1), false (or 0). |
loop= |
false |
[#][box-common-options-loop] Whether to loop the box until it exits with a non-zero code. Mainly useful for menus or when used in combination with [abortOnCallbackFailure=true][box-common-options-abort_on_callback_failure] to control the loop granularly. Possible values: true (or 1), false (or 0). |
hideBreadcrumb= |
false |
[#][box-common-options-hide_breadcrumb] Whether to hide the box from the breadcrumbs stack displayed at the top of the screen. Possible values: true (or 1), false (or 0). |
sleep= |
|
[#][box-common-options-sleep] Sleep (delay) for the given number of seconds after the box exits with a zero code. Useful when a pause is needed before displaying the next box. NOTE: this is not the same as using Dialog’s --sleep option. Instead, the sleep command will be used after the box has been cleared. |
timeout= |
|
[#][box-common-options-timeout] Timeout (exit with error code) if no user response within the given number of seconds. Same as using Dialog’s --timeout option. This behavior is replicated internally by the library when using Whiptail. A timeout of zero seconds is ignored and the decimal part will be dropped. |
term= |
$TERM |
[#][box-common-options-term] The value for the $TERM variable that will be used to render this box. |
( --opt val ... ) |
|
[#][box-common-options-round-bracket-syntax] The special round bracket syntax to pass Whiptail/Dialog-specific options to the box, as if used on the command line. It can be used multiple times in any order. NOTE: since parentheses are special to the shell, you will usually need to escape or quote them. Example usage:
text title='Welcome' text='Hello World!' \( --backtitle 'My backtitle' --fb \) |
yesLabel= |
|
[#][box-common-options-yes_label] Set the text of the Yes button. Same as using Whiptail/Dialog’s --yes-button/--yes-label option. |
noLabel= |
|
[#][box-common-options-no_label] Set the text of the No button. Same as using Whiptail/Dialog’s --no-button/--no-label option. |
okLabel= |
|
[#][box-common-options-ok_label] Set the text of the Ok button. Same as using Whiptail/Dialog’s --ok-button/--ok-label option. |
cancelLabel= |
|
[#][box-common-options-cancel_label] Set the text of the Cancel button. Same as using Whiptail/Dialog’s --cancel-button/--cancel-label option. |
scrollbar= |
false |
[#][box-common-options-scrollbar] Whether to force the display of a vertical scrollbar. Same as using Whiptail/Dialog’s --scrolltext/--scrollbar option. Possible values: true (or 1), false (or 0). |
topleft= |
false |
[#][box-common-options-topleft] Whether to put window in top-left corner. Same as using Whiptail/Dialog’s --topleft/--begin 0 0 option. Possible values: true (or 1), false (or 0). |
help |
|
[#][box-common-options-help] Print the usage screen and exit. |
The += operator will concatenate with the previous <option>= value, e.g.,
info \
title='My very long ' \
title+='box title'
Calendar
Component to set up a new calendar box and perform drawing to the terminal. Corresponds to the --calendar argument in Dialog.
[!NOTE]
In Whiptail, this feature is emulated using an input field with validation.
The output (as well as the input) defaults to the format dd/mm/yyyy.
Demo | Show example code

List of commands:
calendar <options>
Sets up a new calendar box and draws it.
| Option |
Default |
Description |
day= |
(current day) |
[#][calendar-options-day] The day of the calendar. Example: 25. |
month= |
(current month) |
[#][calendar-options-month] The month of the calendar. Example: 12. |
year= |
(current year) |
[#][calendar-options-year] The year of the calendar. Example: 2024. |
dateFormat= |
%d/%m/%Y |
[#][calendar-options-date_format] The format of the outputted date string. NOTE: in Dialog, the --date-format option will be used, which relies on strftime, whereas in Whiptail, the date command will be used. So, there may be slight differences in the format specifiers. |
forceInputBox= |
false |
[#][calendar-options-force_input_box] Whether to force use of the input box instead of the Dialog’s calendar. Possible values: true (or 1), false (or 0). |
See Common Options
Confirm
Component to set up a new confirm box and perform drawing to the terminal. Corresponds to the --yesno argument in Dialog/Whiptail.
Demo | Show example code

List of commands:
confirm <options>
Sets up a new confirm box and draws it.
See Common Options
Edit
Component to set up a new edit box and perform drawing to the terminal. Corresponds to the --editbox argument in Dialog.
In Whiptail, unless [editor][edit-options-editor] option is provided, the default editor will be used instead.
Demo | Show example code

List of commands:
edit <options>
Sets up a new edit box and draws it.
| Option |
Default |
Description |
file=
file+= |
|
[#][edit-options-file] The path to a file whose contents to edit. |
editor=
editor+= |
|
[#][edit-options-editor] The text editor to use. If an empty string is provided, the “good” default text editor will be determined via Debian’s sensible-editor helper command. Otherwise, the editor from the $EDITOR or $VISUAL environment variables, or one of nano, nano-tiny, or vi. This option can be used with Dialog as well to replace the edit box. |
inPlace= |
false |
[#][edit-options-in_place] Whether to edit the file in place after the box/editor exits. Possible values: true (or 1), false (or 0). |
See Common Options
Component to set up a form box and perform drawing to the terminal. Corresponds to the --form, --mixedform
& --passwordform arguments in Dialog.
In Whiptail, this feature is emulated using a normal menu and an input box to edit the fields.
Use up/down arrows (or control/N, control/P) to move between fields.
Unless a callback is specified via [callback][box-common-options-callback] option on the box, on exit, the contents
of the form-fields are written to the standard output, each field separated by a newline. The text used to fill
non-editable fields ([width][form_field-options-width] is zero or negative) is not written out.
Demo | Show example code

List of commands:
form <options>
Sets up a new form box.
| Option |
Default |
Description |
formHeight= |
auto |
[#][form-options-form_height] The form height, which determines the amount of rows to be displayed at one time, but the form will be scrolled if there are more rows than that. Use auto or 0 to auto-size to fit the contents. Can be denoted using percent sign, (e.g., 50%), to adjust dynamically based on the amount of rows. |
columns= |
1 |
[#][form-options-columns] The number of columns per row before wrapping fields to a new line. Using this, will effectively lay out, align, and distribute fields within the Dialog’s window.- If set to
0, all the fields should be manually positioned using coordinates. - If set to
1 or higher, fields will be arranged automatically. The individual field coordinates can still be overridden.
|
fieldWidth= |
|
[#][form-options-field_width] The default field width. |
fieldMaxLength= |
|
[#][form-options-field_max_length] The default permissible length of the data that can be entered in the fields. |
[ opt=val ... ] |
|
[#][form-options-square-bracket-syntax] The special square bracket syntax to add form-fields, which accepts [formField][form_field] options as-is. For example:
form title=‘My form’ [ title=‘First Name’ width=10 ] [ … ] |
See Common Options
formField <options>
Adds a form entry. This can only be used after the form box has been set up.
Fields will appear in the form in the order they are added.
| Option |
Default |
Description |
type= |
input |
[#][form_field-options-type] The type(s) of the field. The field can combine multiple types, for example: hidden|readonly.| Possible values | |
|---|
input | A standard input field that allows to enter and edit text | hidden | A field that stores sensitive data not visible to the user, like passwords | readonly | A non-editable field that displays information to the user, similar to a label |
|
title=
title+= |
"" |
[#][form_field-options-title] The title/label of the field. |
value=
value+= |
"" |
[#][form_field-options-value] The initial value of the field. |
width= |
0 |
[#][form_field-options-width] The width of the field that determines the number of characters that the user can see when editing the value.- If width value is 0, the field cannot be altered, and the contents of the field determine the displayed-length.
- If width value is negative, the field cannot be altered, and the negated value is used to determine the displayed-length.
|
maxlength= |
0 |
[#][form_field-options-maxlength] The permissible length of the data that can be entered in the field. When value is 0, the value of [width][form_field-options-width] is used instead. |
titleX= |
|
[#][form_field-options-title_x] The x-coordinate of the field’s title within the form’s window. This is automatically computed if [columns][form-options-columns] option is > 0, and a value starting with + or - can be used to adjust (increase or decrease) the automatically computed title’s position by that amount. The unit of measurement is terminal columns. |
titleY= |
|
[#][form_field-options-title_y] The y-coordinate of the field’s title within the form’s window. This is automatically computed if [columns][form-options-columns] option is > 0, and a value starting with + or - can be used to adjust (increase or decrease) the automatically computed title’s position by that amount. The unit of measurement is terminal rows. |
valueX= |
|
[#][form_field-options-value_x] The x-coordinate of the field’s value within the form’s window. Typically, you want it to be ${#title} + 2 (+2 is for padding) in order for it to be positioned next to the title. This is automatically computed if [columns][form-options-columns] option is > 0, and a value starting with + or - can be used to adjust (increase or decrease) the automatically computed value’s position by that amount. The unit of measurement is terminal columns. |
valueY= |
|
[#][form_field-options-value_y] The y-coordinate of the field’s value within the form’s window. Typically, you want it to be the same as [titleY][form_field-options-title_y]. This is automatically computed if [columns][form-options-columns] option is > 0, and a value starting with + or - can be used to adjust (increase or decrease) the automatically computed value’s position by that amount. The unit of measurement is terminal rows. |
help |
|
[#][form_field-options-help] Print the usage screen and exit. |
formDraw
Performs the actual drawing of the form. This can only be used after the form box has been fully set up.
| Option |
Description |
help |
[#][form_draw-options-help] Print the usage screen and exit. |
Info
Component to set up a new input box and perform drawing to the terminal. Corresponds to the --infobox argument in Dialog/Whiptail.
[!TIP]
Due to an old bug, Whiptail fails to
render the info box in an xterm-based terminals (e.g., gnome-terminal). As a workaround, boxlib
implicitly uses linux terminfo whenever $TERM matches xterm* or *-256color. The linux
terminfo has color support, but if it doesn’t work for you, try setting the [term][box-common-options-term]
option to vt220 or ansi instead.
Demo | Show example code

List of commands:
info <options>
Sets up a new info box and draws it.
| Option |
Default |
Description |
clear= |
false |
[#][info-options-clear] Whether to clear the screen after the box exits. Unless specified otherwise, this option is implicitly set to true when combined with the [sleep][box-common-options-sleep] option. Possible values: true (or 1), false (or 0). |
See Common Options
Component to set up a new input box and perform drawing to the terminal. Corresponds to the --inputbox & --passwordbox arguments in Dialog/Whiptail.
Demo
input | Show example code

password | Show example code

List of commands:
input <options>
Sets up a new input box and draws it.
| Option |
Default |
Description |
type= |
text |
[#][input-options-type] The type of the input box. Possible values: text, password. |
value=
value+= |
"" |
[#][input-options-value] The value used to initialize the input string. |
See Common Options
List
Component to set up a new list box, add choice entries and perform drawing to the terminal. Corresponds to the --buildlist, --checklist, --radiolist &--treeview arguments in Dialog/Whiptail.
[!NOTE]
In Whiptail, the buildlist feature is emulated using the checklist box.
The treeview feature is emulated using the radiolist box.
Demo
build list | Show example code

checkbox list | Show example code

radiobox list | Show example code

tree list | Show example code

List of commands:
list <options>
Sets up a new list box.
| Option |
Default |
Description |
type= |
check |
[#][list-options-type] The type of the list box.| Possible values | |
|---|
build | displays two lists, side-by-side. The results are written in the order displayed in the selected-window. | check | similar to a menu, but allows to select either many entries or none at all. The results are written in the order displayed in the window. | radio | similar to a menu, but allows to select either a single entry or none at all. | tree | similar to a radio list, but displays entries organized as a tree. The depth is controlled using the [depth][list_entry-options-depth]. The entry [title][list_entry-options-title] is not displayed. After selecting an entry, the entry title is the output. |
|
listHeight= |
auto |
[#][list-options-list_height] The list height, which determines the amount of choices to be displayed at one time, but the list will be scrolled if there are more entries than that. Use auto or 0 to auto-size to fit the contents. Can be denoted using percent sign, (e.g., 50%), to adjust dynamically based on the amount choices. |
prefix= |
|
[#][list-options-prefix] Whether to prefix the entry titles in the list with enumeration, alphabetic letter, or both. This is especially useful for quickly selecting a choice using the keyboard. Unless the [keepPrefix][list-options-keep_prefix] option is used, the prefix will be stripped off before printing/returning the result.| Possible values | |
|---|
num | cardinal number: 1, 2, 3 … 15, 16 … | alpha | alphabet letter: a-z (after z, it goes back to a) | alphanum | alphanumeric: 1-9,a-z (after z, it goes back to 1) | alphanum0 | full alphanumeric: 0-9,a-z (after z, it goes back to 0) | alphanum1 | hybrid alphanumeric: 1-9,0,a-z(after z, it goes back to 1) |
|
keepPrefix= |
false |
[#][list-options-keep_prefix] Whether to keep the prefix in the selected entry when printing/returning the result. This can be useful if you want to use the prefix initials to match entries. Possible values: true (or 1), false (or 0). |
[ opt=val ... ] |
|
[#][list-options-square-bracket-syntax] The special square bracket syntax to add list choices, which accepts [listEntry][list_entry] options as-is. For example:
list title=‘My list’ [ title=‘Option 1’ summary=‘Summary 1’ ] [ … ] |
See Common Options
listEntry <options>
Adds a choice entry. This can only be used after the list box has been set up.
Choice entries will appear in the list in the order they are added.
| Option |
Default |
Description |
title=
title+= |
"" |
[#][list_entry-options-title] The title of the choice entry. |
summary=
summary+= |
"" |
[#][list_entry-options-summary] The summary of the entry. |
selected= |
false |
[#][list_entry-options-selected] Whether to preselect the choice. Possible values: true (or 1), false (or 0). |
depth= |
0 |
[#][list_entry-options-depth] The depth of the entry in the tree list. |
callback= |
|
[#][list_entry-options-callback] The callback to invoke when this entry is selected in the list. The callback will be:- invoked as a local function if it ends with
() - executed if it’s a file with the “execute” bit set
- sourced as a shell script file if it’s none of the above
In all cases, the callback should expect the title of the selected entry as first input parameter. When executed, the $? variable will contain the exit code from the renderer (Whiptail/Dialog).
NOTE:- This option takes precedence over the list’s [
callback][box-common-options-callback] parameter. - The callback execution will be sandboxed, i.e., it will run in a sub-shell. This ensures the interaction is isolated.
- If the callback is a relative path to a file, then it will be searched starting from the working directory.
Also, the CWD will be changed to where the callback file is located before executing/sourcing it. To disable, set [changeToCallbackDir=false][box-common-options-change_to_callback_dir].
|
help |
|
[#][list_entry-options-help] Print the usage screen and exit. |
listDraw
Performs the actual drawing of the list. This can only be used after the list box has been fully set up.
| Option |
Description |
help |
[#][list_draw-options-help] Print the usage screen and exit. |
Component to set up a new menu box, add menu entries and perform drawing to the terminal. Corresponds to the --menu & --inputmenu arguments in Dialog/Whiptail.
[!NOTE]
In Whiptail, the input menu is simulated using a normal menu and an input box allowing you to edit
the menu entry summary when it is selected, similar to how it works in Dialog.
Demo
menu | Show example code

input menu | Show example code

List of commands:
menu <options>
Sets up a new menu box.
| Option |
Default |
Description |
menuHeight= |
auto |
The menu height, which determines the amount of entries to be displayed at one time, but the menu will be scrolled if there are more entries than that. Use auto or 0 to auto-size to fit the contents. Can be denoted using percent sign, (e.g., 50%), to adjust dynamically based on the amount of menu entries. |
prefix= |
|
Whether to prefix the entry titles in the list with enumeration, alphabetic letters, or both. This is especially useful for quickly selecting an entry using the keyboard. Unless the [keepPrefix][menu-options-keep_prefix] option is used, the prefix will be stripped off before printing/returning the result.| Possible values | |
|---|
num | cardinal number: 1, 2, 3 … 15, 16 … | alpha | alphabet letter: a-z (after z, it goes back to a) | alphanum | alphanumeric: 1-9,a-z (after z, it goes back to 1) | alphanum0 | full alphanumeric: 0-9,a-z (after z, it goes back to 0) | alphanum1 | hybrid alphanumeric: 1-9,0,a-z(after z, it goes back to 1) |
|
keepPrefix= |
false |
Whether to keep the prefix in the selected entry when printing/returning the result. This can be useful if you want to use the prefix initials to match entries. Possible values: true (or 1), false (or 0). |
rename= |
false |
Whether renaming the menu entry summary is allowed. The output after renaming will follow this format: RENAMED <entry> <summary> After renaming, the exit status is equal to 3. Possible values: true (or 1), false (or 0). |
[ opt=val ... ] |
|
The special square bracket syntax to add menu entries, which accepts [menuEntry][menu_entry] options as-is. For example:
menu title=‘My menu’ [ title=‘Option 1’ summary=‘Summary 1’ ] [ … ] |
See Common Options
Adds a menu entry. This can only be used after the menu box has been set up.
Menu entries will appear in the menu in the order they are added.
| Option |
Default |
Description |
title=
title+= |
"" |
The title of the menu entry. |
summary=
summary+= |
"" |
The summary of the entry. |
selected= |
false |
Whether to preselect the entry. Same as --default-item argument in Whiptail/Dialog. Possible values: true (or 1), false (or 0). |
callback= |
|
The callback to invoke when this entry is selected in the menu. The callback will be:- invoked as a local function if it ends with
() - executed if it’s a file with the “execute” bit set
- sourced as a shell script file if it’s none of the above
In all cases, the callback should expect the title of the selected entry as first input parameter. When executed, the $? variable will contain the exit code from the renderer (Whiptail/Dialog).
NOTE:- This option takes precedence over the menu’s [
callback][box-common-options-callback] parameter. - The callback execution will be sandboxed, i.e., it will run in a sub-shell. This ensures the interaction is isolated.
- If the callback is a relative path to a file, then it will be searched starting from the working directory.
Also, the CWD will be changed to where the callback file is located before executing/sourcing it. To disable, set [changeToCallbackDir=false][box-common-options-change_to_callback_dir].
|
help |
|
Print the usage screen and exit. |
menuDraw
Performs the actual drawing of the menu. This can only be used after the menu box has been fully set up.
| Option |
Description |
help |
Print the usage screen and exit. |
Pause
Component to set up a new pause box and perform drawing to the terminal. Corresponds to the --pause argument in Dialog.
In Whiptail, this feature is emulated using a menu box.
Demo | Show example code

List of commands:
pause <options>
Sets up a new pause box and draws it.
| Option |
Default |
Description |
seconds= |
|
[#][pause-options-seconds] The amount of seconds to pause, after which the box will timeout. The decimal part will be dropped. |
See Common Options
Program
Sets up a new program box that will display the output of a command. Corresponds to the --prgbox,
--programbox & --progressbox arguments in Dialog.
In Whiptail, this feature is emulated using an input field with validation.
[!IMPORTANT]
When using process substitution to feed the program box, it’s crucial to wait for the process
substitution’s PID to ensure correct behavior of the box, especially with [hideOk="false"][program-options-hide_ok]
option. See example:
{ /bin/cmd; } > >(program text='Working in progress...') 2>&1
wait $!
# Pitfall: the result of $! could be empty if process substitution is fed by
# an external command ('/bin/cmd' in this case). As a workaround, wrap external
# command call using a Bash function or put everything in {...} block and
# redirect the output of the block as shown above.
# For more details, see https://unix.stackexchange.com/a/524844
The rationale behind that, is because the program box reads your program’s output in a separate
subshell. Once your program finishes, the subshell running the program box will be
effectively detached from the main Bash process. By explicitly waiting for it before exiting your
script or launching another box, you ensure the program box can clean up the screen and restore
TTY input settings.
Also, this strictly requires Bash v4.4 for the process substitution’s PID to be waitable.
For Bash v4.3, use flock-style locking mechanism to achieve the same.
Demo | Show example code

List of commands:
program <options>
Sets up a new box that will display the output of a command.
| Option |
Default |
Description |
command=
command+= |
|
[#][program-options-command] The command(s) to execute via sh -c <command> whose output will be displayed in the box. If omitted, then the output will be read from stdin. |
hideOk= |
false |
[#][program-options-hide_ok] Whether to hide the OK button after the command has completed. Possible values: true (or 1), false (or 0). |
Progress
Component to set up a new progress box, make adjustments on-the-fly, and perform drawing to the terminal. Corresponds to the --gauge & --mixedgauge arguments in Dialog/Whiptail.
In Whiptail, the mixed progress is simulated using a normal progress.
Demo
progress | Show example code

mixed progress | Show example code

List of commands:
progress <options>
Sets up a new progress box and draws it.
| Option |
Default |
Description |
value= |
0 |
[#][progress-options-value] The initial value to calculate the percentage of the progress bar. If [total][progress-options-total] option is not set, then this value is the % value of the progress bar. Can be updated using [progressSet][progress_set-command] command. Decimal part will be dropped. |
total= |
0 |
[#][progress-options-total] The initial total or complete value used to calculate the % value that will be displayed in the progress bar. Here’s the general formula: percentage=value/total*100. Can be updated using [progressSet][progress_set-command] command. Decimal part will be dropped. |
entry= |
|
[#][progress-options-entry] The entry (row) name to add. Each entry must be paired with a [state][progress-options-state] option. Any amount of entries can be added, or you can add them later with [progressSet][progress_set-command] command. The entry name should be unique, so that its state can be updated using [progressSet][progress_set-command] command. IMPORTANT: the number of [entry][progress-options-entry] and [state][progress-options-state] options must be equal. The following example will fail (2 entries and 1 state): progress entry=‘Entry1’ state=“$PROGRESS_N_A_STATE” entry=‘Entry2’ |
state= |
|
[#][progress-options-state] The state of the entry. The entry state can be any string. If the string starts with a leading - (e.g., -20), then it will be suffixed with a % sign, such as 20%. There are 10 special entry states encoded as digits (0-9), publicly available as numeric constant variables: PROGRESS_SUCCEEDED_STATE (0) | Succeeded | PROGRESS_FAILED_STATE (1) | Failed | PROGRESS_PASSED_STATE (2) | Passed | PROGRESS_COMPLETED_STATE (3) | Completed | PROGRESS_CHECKED_STATE (4) | Checked | PROGRESS_DONE_STATE (5) | Done | PROGRESS_SKIPPED_STATE (6) | Skipped | PROGRESS_IN_PROGRESS_STATE (7) | In Progress | PROGRESS_BLANK_STATE (8) | (blank) | PROGRESS_N_A_STATE (9) | N/A |
|
[S
README 内容过长,已截取前 64 KB。完整内容请前往 GitHub 仓库查看。
评论