Linux terminal output libraries

Recently I wanted to build a small application to ask the user for some input before generating some output (as all programs do). For this task I decided to use a small command line script to do the job as it was the best fit for the job (a linux based install script). The script will run in the terminal so it would be nice to use a fancy library to ask the input in various ways (checkbox, radio, menu, progress, etc). So I started searching on the internet.

During my search I found a couple of libraries: dialog, whiptail & zenity. This blog post I will talk about these three libraries, although there might be many more/better libraries available.

Dialog

Dialog is an application used in shell scripts which displays text user interface widgets. It uses the curses or ncurses library.

Dialog dates from 1999 and is the oldest of the three libraries evaluated in this blog post. In 2005 the license was changed to LGPL (from GPL).

Example: Text
dialog \
        --title "My Text Input" \
        --inputbox "What is your name" 8 40 "Dirk Engels"
Example: Checkbox
dialog \
        --title "My Checkbox Input" \
        --inputbox "What is your name" 8 40 "Dirk Engels"
Useful resources

Whiptail

Literally copy & pasted from the whiptail website: "whiptail is a program that will let you present a variety of questions or display messages using dialog boxes from a shell script. Currently, these types of dialog boxes are implemented: yes/no box, menu box, input box, message box, text box, info box, checklist box, radiolist box gauge box, and password box."

From its README: whiptail is designed to be drop-in compatible with dialog(1), but has less features: some dialog boxes are not implemented, such as tailbox, timebox, calendarbox, etc.

Example: Text
whiptail \
        --title "My Text Input" \
        --inputbox "What is your name" \
        10 60 "Dirk Engels"
Example: Checkbox
whiptail --title "My Checkbox Input" --checklist \
        "How linux.byexamples can be improved?" 15 60 4 \
        "pictures" "More pictures" ON \
        "posts" "More complete post" ON \
        "installation" "Includes Installation guidelines" OFF \
        "questions" "Create a forum for question queries" OFF
Useful resources

Zenity

Zenity is a tool that allows you to display GTK dialog boxes in commandline and shell scripts. According to Wikipedia regarding zenity: "Like tools such as whiptail and dialog, zenity allows easy creation of GUIs,[1] though it has fewer features than more complex GUI-creation tools."

Example: Text
zenity \
        --title="My Text Input" \
        --text="What is your name" \
        --entry --entry-text="Dirk Engels"
Example: Checkbox
zenity \
        --title "My Checkbox Input" \
        --list \
        --text "How linux can be improved?" \
        --column "Pick" \
        --column "options" \
                TRUE "More pictures" \
                TRUE "More complete post" \
                FALSE "Includes Installation guidelines" \
                FALSE "Create a forum for question queries" \
        --checklist
Usefull resources

Kdialog

kdialog allows you to display dialog boxes from shell scripts. The syntax is very much inspired from the "dialog" command (which shows text mode dialogs).

However the width and height attributes have been removed for most dialogs - Qt/KDE have layouts ;)

Example: Text
kdialog \
        --title "Input dialog" \
        --inputbox "What is your name" "Dirk Engels"
Example: Checkbox
kdialog \
        --title "My Checkbox Input" \
        --checklist "How linux can be improved?" \
        "American English" "American English" off \
        "French" French off \
        "Dutch" Dutch on 
Usefull resources

Comparison

Component Dialog Whiptail Zenity Kdialog
Message X X X X
YesNo X X X X
Input X X X X
Password X X X X
Menu X X X X
Radio X X X X
Check X X X X
Progress X X X X
File X - X X
Range - - X -
Calendar X - X X
Time X - X -

Conclusion

Rendered Content in 0.002 seconds

Rendered UI Widgets in 0.003 seconds

Want to see the cheezy internals?
twig layout template | twig page template | json data