Dialog: Using Dialog boxes to interact with users on a Linux console.


You can’t throw in a GUI for an application that will be run on an enviornment without X. Does that mean you’re left to live with bland command-line prompts for interaction? Think again.

Ever done a text-based install of a Linux distribution? If yes, then I bet you haven’t missed out on those colourful boxes, pitched in combinations of red and blue or yellow and blue, requesting you to type in input and displaying output in return. If you have ever installed Slackware, any of the BSDs, or Debian, I am sure you can’t have overlooked those boxes. What are those? Don’t they look cool? Wouldn’t you want to have one to handle interactions with the enviornment on your command-line application(s)? If you’re anything like me who writes only applications which run from the console, sure as hell you do. I’ve got one word for you: dialog.

Yes! Dialog! Dialog is a program you can find on almost any Linux distribution. It is a program that displays colourful dialog boxes for interaction with the user. It can display information boxes, which contain nothing but text to display on the screen inside a colourful box, menu bars, input boxes, check boxes, etc. You name it, dialog has it.

The manpage documents dialog(1) in detail, being the all-in-one manual to understand how to use dialog and start using it. I see no point in re-hashing the contents of the manpage in my own words. But, yes, I think a simple BASH script to make use of the dialog utility to create a couple of dialogs to take input from user would be sufficient to get the curious onlooker started.

#!/bin/bash

dialog --backtitle "Dialog Test Example" --title "Network Settings"
--no-shadow --menu "DHCP or Manual" 0 0 0 "dhcp" "Enable DHCP"
"manual" "Manual Ip Setting" 2> /tmp/output.file

dialog --backtitle "Dialog Test Example" --title "IP Settings"
--no-shadow --inputbox "EnterIP:" 0 0 "192.168.1.10" 2> /tmp/output.file

# End

Execute the script and be mesmerised by the magic of dialog. By the way, do take a look at the file /tmp/output.file when you’re done running this simple script. ;-)

6 thoughts on “Dialog: Using Dialog boxes to interact with users on a Linux console.

  1. Heh, yea. I used to think so too, until, one boring day, while editing a couple of maketag scripts found on Slackware CDs, I bumped across “dialog”. I’d like to think I stumbled over a treasure chest. ;-)

  2. Dialog is a stultifyingly stupid piece of shit, adding no further functionality to a choice-driven script than colors.

    But hey, if you like colors, it is soooooo cooooool

  3. If you write your scripts to use dialog they can easily be ported to X by replacing the dialog command with the dialogx command (also found in many distro’s). You can also easily determine if you are in a terminal (use dialog) or if you are in X (use dialogX).

    Ideal for simple utility type applications (and very fast).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s