Introduction to Linux programming-Dialog

Source: Internet
Author: User
Introduction to Linux programming-Dialog -- general Linux technology-Linux programming and kernel information. For more information, see the following section. Dialog is used in shell scripts. In fact, when you download Linux Kernel, there is a scripts/lxdialog Directory, which is actually the original dialog code, only Linux kernel changes the name to lxdialog to avoid conflicts with the original dialog. When you use "make menuconfig", you are using the dialog tool. In addition, the Slackware installer actually uses the dialog tool as the interface.

You can call dialog using shell script or perl to provide a friendly user interface.

With the dialog tool, you can use Shell Script to complete complex operation interfaces without the need to write "difficult" ncurses programs, greatly reducing product development time.


You can use "man dialog" to check its usage. Here we will make some usage and demonstration of dialog.

Dialog -- clear

The entire screen is cleared and left

Dialog -- create-rc file

Dialog supports dynamic planning, which generates a sample.

Dialog [-- title] [-- backtitle]
[-- Clear] [-- separate-output] box-options

-- Title

Title text on the dialog box

-- Backtitle

Desktop background title

Box-options

Dialog currently provides yes/no box, menu box, input box, message box, text
There are nine widgets in box, info box, checklist box, radiolist box, and gauge box.

Exit Status

If you press Yes or OK, 0 is returned. No or Cancel returns 1. If you press ESC or an error occurs,-1 is returned.

-- Yesno text height width

[Foxman @ foxman/] # dialog -- title "hello" -- backtitle "Dialog"
-- Yesno "Is everything okay" 20 60


-- Msgbox text height width

[Foxman @ foxman/] # dialog -- title "hello" -- backtitle "Dialog"
-- Msgbox "Is everything okay" 20 60


-- Infobox text height width

[Foxman @ foxman dialog] # dialog -- title "hey" -- backtitle "Dialog"
-- Infobox "Is everything okay? "10 60

Infobox leaves immediately after the message is displayed. In the console, the message is left,
At Terminal, the X Terminal will immediately clear the message, and the Screen Shot cannot be caught. Therefore
No ScreenShot. You can test it on the console.

-- Inputbox text height width [init]

[Foxman @ foxman dialog] # dialog -- title "hey" -- backtitle "Dialog"
-- Inputbox "Is everything okay? "10 60" yes"




-- Textbox file height width

[Foxman @ foxman copyright] # dialog -- title "Array 30" -- backtitle "All
For Chinese "-- textbox array30 20 75


Textbox is like a simple text viewer, which displays the text in the file.

-- Menu text height width menu-height [tag item]...

[Foxman @ foxman dialog] # dialog -- title "Menu Example" -- menu "MENU"
20 60 4 tag1 "item1" tag2 "item2" tag3 "item3" tag4 "item4"




-- Checklist text height width list-height [tag item status]
...

[Foxman @ foxman dialog] # dialog -- title "CheckList Example"
-- Checklist "Check List" 20 60 4 tag1 "item1" on tag2 "item2" off
Tag3 "item3" on tag4 "item4" off


-- Radiolist text height width list-height [tag item status
]...

[Foxman @ foxman dialog] # dialog -- title "RadioList Example"
-- Radiolist "Radio List" 20 60 4 tag1 "item1" on tag2 "item2" off
Tag3 "item3" on tag4 "item4" off


-- Gauge text height width percent

[Foxman @ foxman dialog] # dialog -- title "Installation" -- backtitle
"Star Linux" -- gauge "Linux Kernel" 10 60 50


After the gauge widget is started, it reads percent from stdin and ends when EOF is read.


Advanced use with Shell Script

It is not enough to know how to use each function. Generally, you need to know how to use it with scripts.
Yesno, inputbox, menu, checklist, radiolist, and gauge are required.

Yesno

Example
#! /Bin/sh

DIALOG = dialog

If parameters $ DIALOG -- title "WCW v. s. NWO" -- backtitle "Wrestling "\
-- Yesno "Are you ready to rumble? "5 60; then
Echo "Yeahhhhh"
Else
Echo "Nap ..."
Fi

Inputbox

Example
#! /Bin/sh

DIALOG = dialog

If else $ DIALOG -- title "The future is here "\
-- Inputbox "Where do you want to go tomorrow? "\
10 75 "Penguin" 2> my_own_destiny
Then
Way = 'cat my_own_destiny'
Echo "My way is running $ way"
Else
Echo "freak out"
Fi

Menu

#! /Bin/sh

If dialog -- title "title "\
-- Menu "MENU" 20 60 14 \
Tag1 "item1" tag2 "item2" 2> select
Then
Selection = 'cat select'
Echo "my selection is selected $ selection"
Else
Echo "go"
Fi

Checklist

#! /Bin/sh

If dialog -- title "title "\
-- Checklist "checklist" 20 60 14 \
Tag1 "item1" on tag2 "item2" off 2> select
Then
Selections = 'cat select'

Echo "My selections are :"
For I in orders $ selections; do
Echo done $ I
Done

Else
Echo "go"
Fi

Radiolist

#! /Bin/sh

If dialog -- title "title "\
-- Radiolist "checklist" 20 60 14 \
Tag1 "item1" on tag2 "item2" off 2> select
Then
Selection = 'cat select'
Echo "My selection is selected $ selection"
Else
Echo "go"
Fi

Gauge

So far, gauge seems to have been a problem, and it is also a problem to write files. The attached sample program is also unavailable and is not recommended for use (I cannot play it myself, if you try it out, please send me a letter ).


OK STATION, Webmaster, Brian Lin
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.