Open In App

Creating dialog boxes with the Dialog Tool in Linux

Last Updated : 22 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The dialog package is a nifty little tool that was originally created by Savio Lam and is currently maintained by Thomas E. Dickey. This package actually recreates standard Windows dialog boxes in a text environment using ANSI escape control codes. These dialog boxes can be easily incorporated into your shell scripts to interact with your script users.

The dialog package isn’t installed in all Linux distributions by default, but it’s almost always included in the software repository. For Ubuntu Linux, the following command can be used to install the package.

sudo apt-get install dialog 

It installs the dialog package plus the required libraries for the system.

The format for the box options is as follows

There are many dialog widgets. Among them, a few of them are:

Dialog widgets

1. Calendar – Provides a calendar to display the selected date

 The format for this widget is

--calendar     <text> <height> <width> <day> <month> <year>

The command which we  wrote in the script file is

dialog --calendar 'calendar'  5 50 30 6 2021

calendar widget

After running the script, we get the calendar as shown below.

2. Checklist – Displays multiple entries where each entry can be turned on or off.

The format for this widget is

–checklist    <text> <height> <width> <list height> <tag1> <item1> <status1>…

The command which we  wrote in the script file is 

dialog –checklist  ‘checklist’ 15 10 10 ‘apple’ 5 ‘on’ ‘banana’ 2 ‘off’ ‘coco’ 3 ‘on’ ‘delta’ 4 ‘off’

checklist widget

After running the script, we get the checklist as shown below.

3. Form – This allows you to build a form with labels and text fields to be filled out.

The format for this widget is

 –form <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> … 

Here, flen is the length of the field, and ilen is the length of the field that allows input to move between fields.

The command which we  wrote in the script file is

 dialog   –form “Please enter the information” 12 40 4 “Name :” 1 1 “” 1 12 15 0 “Age: ” 2 1 “” 2 12 15 0 “Mail id:” 3 1 “” 3 12 15 0

Form widget

After running the script, we get the form as shown below.

4. Gauge – Allows you to display the gauge progress window

The format for this widget is

 --gauge <text> <height> <width> [<percent>]

The command which we  wrote in the script file is

dialog --gauge  "progress.." 10 20 40

gauge widget

After running the script, we get the window as shown below.

 5. Message box – Displays a message and requires the user to select an OK button

The format for this widget is

-- msgbox <text> <height> <width>

The command which we  wrote in the script file is

dialog --msgbox  "This is a message" 10 25

message box widget

After running the script, we get the message box as shown below.

6. Fselect – Provides a file selection window to browse for a file.

The format for this widget is

-- fselect <filepath> <height> < width >

The command which we  wrote in the script file is

dialog --title "fselect" --fselect /documents 15 40

fselect widget

After running the script, we get the window as shown below.

7. Infobox – Displays a message without waiting for a response.

The format for this widget is

--infobox      <text> <height> <width>

The command which we  wrote in the script file is

dialog  --infobox   "This is a message" 15 30

inforbox widget

After running the script, we get the information box as shown below.

8. Inputbox – Displays a single text form box for text entry.

The format for this widget is

 --inputbox     <text> <height> <width> [<init>]

The command which we  wrote in the script file is

dialog  --inputbox "Enter the name" 15 30 'enter here'

inputbox widget

After running the script, we get the input box as shown below.

9. Inputmenu – This widget provides an editable menu.

The format for this widget is

 –inputmenu    <text> <height> <width> <menu height> <tag1> <item1>…

The command which we  wrote in the script file is

dialog –inputmenu “Edit if necessary” 12 45 25 1 “hello” 2 “good morning” 3 ” take care “

inputmenu widget

After running the script, we get the window to edit as shown below.

10. Menu – This widget displays a list of selections from which to choose.

The format for this widget is

–menu         <text> <height> <width> <menu height> <tag1> <item1>…

The command which we  wrote in the script file is

dialog –menu “Choose the option” 12 45 25 1 “apple” 2 “banana” 3 “mango”

menu widget

After running the script, we get the window to edit as shown below.

11. Pause – It displays a meter showing the status of a specified pause period.

The format for this widget is

--pause <text> <height> <width> <seconds>

The command which we  wrote in the script file is

dialog --pause "pause" 20 40 30

Pause widget

After running the script, we get the window as shown below.

The timer starts running….. out of which two images are depicted below

12. Mixed form – This widget allows you to build a form with labels and text fields of different forms to be filled out.

The format for this widget is

–mixedform    <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1> <itype>…

The command which we  wrote in the script file is

dialog   –mixedform “Please enter the information” 12 40 4 “Name :” 1 1 “” 1 12 15 0 a “Age: ” 2 1 “” 2 12 15 0 a “Mail id:” 3 1 “” 3 12 15 0 a

Mixed form widget

After running the script, we get the form as shown below.

13. Mixedgauge – allows you to display the gauge progress window with multiple items.

The format for this widget is

--mixedgauge   <text> <height> <width> <percent> <tag1> <item1>...

The command which we  wrote in the script file is

dialog   --mixedgauge   "Gauge box" 10 20 40 app one

Mixedgauge widget

After running the script, we get the window as shown below.

14. Password – This widget displays a single textbox that hides entered text.

The format for this widget is

--passwordbox  <text> <height> <width> [<init>]

The command which we  wrote in the script file is

dialog   --passwordbox   "Password" 10 20

Password widget

After running the script, we get the window as shown below.

15. Passwordform – This widget displays a form with labels and hidden text fields.

The format for this widget is

–passwordform <text> <height> <width> <form height> <label1> <l_y1> <l_x1> <item1> <i_y1> <i_x1> <flen1> <ilen1>…

The command which we  wrote in the script file is

dialog   –passwordform “Please enter the information” 12 40 4 “Password:” 1 1 “” 1 12 15 0 “otp: ” 2 1 “” 2 12 15 0 “secret key:” 3 1 “” 3 12 15 0

Passwordform widget

After running the script, we get the window as shown below.

16. Radiolist – This widget provides a group of menu items where only one item can be selected.

The format for this widget is

–radiolist    <text> <height> <width> <list height> <tag1> <item1> <status1>…

The command which we  wrote in the script file is

dialog –radiolist   ‘radiolist’ 15 10 10 ‘apple’ 5 ‘off’ ‘banana’ 2 ‘off’ ‘coffee’ 3 ‘off’ ‘dessert’ 4 ‘off’

Radiolist widget

After running the script, we get the window as shown below.

17. Program box – This widget lets you display the output of the command in the dialog box.

The format for this widget is

--prgbox       <text> <command> <height> <width>

The command which we  wrote in the script file is

dialog --prgbox   "command" "ls"  10 30

Program box widget

After running the script, we get the window as shown below.

18. Textbox – This widget displays the contents of a file in a scroll window

The format for this widget is

--textbox      <file> <height> <width>

The command which we  wrote in the script file is

dialog –textbox /etc/hosts 10 60

Textbox widget

After running the script, we get the window as shown below.

19. Tailbox – This widget displays text from a file in a scroll window using the tail command.

The format for this widget is

--tailbox      <file> <height> <width>

The command which we  wrote in the script file is

dialog --tailbox /etc/hosts 10 60

tailbox widget

After running the script, we get the window as shown below.

20. Yes no – This widget provides a simple message with Yes and No buttons.

The format for this widget is

--yesno        <text> <height> <width>

The command which we  wrote in the script file is

dialog --yesno "Do you want run the command" 10 30

yesno widgetimage widget

After running the script, we get the window as shown below.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads