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 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).
dialog \ --title "My Text Input" \ --inputbox "What is your name" 8 40 "Dirk Engels"
dialog \ --title "My Checkbox Input" \ --inputbox "What is your name" 8 40 "Dirk Engels"
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.
whiptail \ --title "My Text Input" \ --inputbox "What is your name" \ 10 60 "Dirk Engels"
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
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, though it has fewer features than more complex GUI-creation tools."
zenity \ --title="My Text Input" \ --text="What is your name" \ --entry --entry-text="Dirk Engels"
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
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 ;)
kdialog \ --title "Input dialog" \ --inputbox "What is your name" "Dirk Engels"
kdialog \ --title "My Checkbox Input" \ --checklist "How linux can be improved?" \ "American English" "American English" off \ "French" French off \ "Dutch" Dutch on
- Usage / Trend