GUI Design in dialog shell replaces complicated libncurses Programming

Source: Internet
Author: User

Original article link

 

Cutting-edge

In the past, I wanted to write a bash-like GUI interface, so I had to use the libncurses library in C. I thought it was annoying.

With the dialog tool, you canProgramIn

Use shell script to complete complex operation interfaces, greatly reducing product development time.

Let's take a look at the example below happy

Dialog -- title "hello" -- backtitle "dialog" -- yesno "Is everything okay" 20 60

 You will see (very familiar)

 

 

 

Dialog is used in shell scripts. In fact, when you Download In Linux kernel, there is

The scripts/lxdialog directory is actually the original dialog code, just Linux kernel to avoid

Do not conflict with the original dialog. Change the name to lxdialog. When you use "make menuconfig"

Dialog is used. In addition, the slackware installation program is actually used

The dialog tool is used as the interface.
 

You can call dialog using shell script or Perl to provide

User-friendly interface.
   

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

-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 work with scripts.

.

Yesno, inputbox, menu, checklist, radiolist, and gauge are required.
 

Yesno
 

Example

#! /Bin/sh
 

Dialog = Dialog
 

If $ 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 $ 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 $ 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 $ 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 $ selections; do

Echo $ 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 $ selection"

Else

Echo "go"

Fi
 

Gauge
 

So far, gauge seems to have been a problem, and the file is also written as a problem.

The example 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 ).

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.