This topic was published by and viewed 1464 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author

  • DevynCJohnson
    • Topics - 437
    • @devyncjohnson

    Dialog is a command that scripts can use to make a text-based interface for their scripts. These text-interfaces only work in a terminal (command-line).

    Dialog is a lot like kdialog as far as the syntax is concerned. So, if you know kdialog, then this should be easy to understand. The "dialog" command accepts titles in the format - --title "TITLE"

    The title in the background at the top of the screen is set using the "--backtitle" argument. Both types of titles are optional. However, one required set of parameters is the window dimensions. The very last parameters for the dialog command are the dimensions where the first number is for height and the second is for width. However, some windows place the dimensions before lists.

    Programmers can make scrips that behave based on the exit status of a dialog window. If "yes" or "okay" is pressed, the exit status is "0" while "no" and "cancel" equals "1". Errors and the esc key produce an exit status of negative one (-1). The exit status is read via the "$?" variable and can be used in decision constructs.

    The buttons can be manipulated using special parameters and arguments. To make the "exit" button have a different label, use the "--exit-label" argument with the desired label following in quotes - (--exit-label "Quit"). The same concept applies to the Okay button and Yes button ("--ok-label" and "--yes-label", respectively). An extra button can be made between the "Okay" and "Cancel" buttons by using the "--extra-button" argument. The "Extra" button can be given an alternate label by using the "--extra-label" argument (just like "--exit-label") and the desired label. Again, "--help-button" and "--help-label" work the same way to construct a "Help" button. The cancel button can be removed via "--no-cancel" and so can the "Ok" button using "--no-ok".

    Dialog offers various types of windows. "--yesno" is a yes-or-no window used to ask a question. "--msgbox" simply displays info with the only option being "okay" while "--infobox" offers no button to press.

    dialog --title "Yes or No" --backtitle "EXAMPLE" --yesno "Dialog is easy" 7 25
    dialog --title "Message" --backtitle "EXAMPLE" --msgbox "Dialog is easy" 7 25
    dialog --title "Info" --backtitle "EXAMPLE" --infobox "Dialog is easy" 7 25

    Users can give the program info through typing by using the "--inputbox" window. Such entered data is sent to stderr when submitted. Outputting to stdout can cause problems on some systems that use Dialog.

    To view text files, use "--textbox /FILE/PATH".

    To produce menus with items for selection, use a format like dialog --menu "Pick Something:" HEIGHT WIDTH MENU-WIDTH ITEM-NUM1 ITEM1 ITEM-NUM2 ITEM2

    In the template, the height and width refer to the window dimensions discussed earlier. The menu-width is the size of the menu itself. The ITEM-NUM1 is the number a user can press to select ITEM1. Here is an example - dialog --menu "Ice Cream:" 10 30 7 1 Vanilla 2 Raspberry 3 Chocolate 4 Banana 5 Coffee

    Yes, the window is too small for the menu, but as a result, do so automatically activates the scrolling feature. Users can press 1 through 5 to highlight a choice before pressing "Okay".

    The "--checklist" window is similar to the menu window, except all, some, or no items can be selected. To mark an item for selection, press the space bar. The syntax is just like it is with "--menu" except the programmer needs to add the words "on" or "off" after each item. This is setting the default values. For illustration, we will take our "--menu" example from above and change it to a "--checklist" window.

    dialog --checklist "Ice Cream:" 10 30 7 1 Vanilla off 2 Raspberry off 3 Chocolate off 4 Banana off 5 Coffee off

    If one of the items were to be checked (selected) by default, then set the desired default to "on".

    "--radiolist" is set up just like "--checklist". The difference lies in the behavior; only one item can be chosen.

    A calendar can also be made by dialog. Example - dialog --calendar "Calendar" 10 40

    Users can also browse for files using dialog. The dialog command must contain a path to start within by default. In this example, dialog will open the /usr/ directory. Example - dialog --fselect /usr/ 15 50

    Many other options exist, but these are the most important main ones, in my opinion.

    Further Reading

Viewing 1 post (of 1 total)