linux dialog 源码,Linux dialog详解(图形化shell)

本文详细介绍了dialog工具在密码框、文本框、菜单、文件选择、复选框、日历、进度条、表单和多屏交互等场景下的使用方法,并强调了安全选项如密码隐藏的重要性。通过实例演示和综合应用示例,展示了如何在信息技术项目中实现用户界面交互设计。
摘要由CSDN通过智能技术生成

0818b9ca8b590ca3270a3433284dd417.png

4.密码框

格式:

dialog  --passwordbox text height width [init]

例子:

1

2

# dialog --title "Password"  --passwordbox \

"Please give a password for the new user:"

10

35

0818b9ca8b590ca3270a3433284dd417.png

这样我们的密码就暴露出来了,是不是很不安全,所以通常我们会加上一个安全选项

--insecure   将每个字符用*来显示出来

1

2

# dialog  --title  "Password"  --insecure  \

--

passwordbox

"Please  give  a  password  for the  new  user:"

10

30

0818b9ca8b590ca3270a3433284dd417.png

5.文本框

格式:dialog --textbox file height width

例子:

1

#dialog --title "The fstab" --textbox /etc/fstab  17 40

0818b9ca8b590ca3270a3433284dd417.png

6.菜单框

格式:dialog --menu text height width  menu-height tag1 item1 tag2 item2 …

例子:

1

2

#dialog --title "Pick a choice" --menu "Choose one" 12 35 5 \

1

"say hello to everyone"

2

"thanks for your support"

3

"exit"

0818b9ca8b590ca3270a3433284dd417.png

7.Fselect框(文件选框)

格式:dialog --fselect filepath height width

例子:

1

#dialog --title "Pick one file" --fselect /root/ 7 40

0818b9ca8b590ca3270a3433284dd417.png

8.复选框格式:dialog  --checklist "Test" height width  menu-height  tag1 item1 tag2 item2 … 例子:

1

2

# dialog --backtitle "Checklist" --checklist "Test" 20 50 10 \

Memory

Memory

_Size

1

Dsik

Disk

_Size

2

<

b

>

<

/

b

>

0818b9ca8b590ca3270a3433284dd417.png

9.显示日历格式:dialog --calendar "Date" height width day month year例子:#显示当前日期

1

# dialog --title "Calendar" --calendar "Date" 5 50

0818b9ca8b590ca3270a3433284dd417.png

#显示指定日期

1

# dialog --title "Calendar" --calendar "Date" 5 50 1 2 2013

0818b9ca8b590ca3270a3433284dd417.png

10.进度框架

格式:dialog --gauge text height width  []

例子:

#固定进度显示

1

#dialog --title "installation pro" --gauge "installation" 10 30 10

0818b9ca8b590ca3270a3433284dd417.png

#实时动度进度

1

2

#for i in {1..100} ;do echo $i;done | dialog --title \

"installation pro"

--

gauge

"installation"

10

30

0818b9ca8b590ca3270a3433284dd417.png

#编辑到脚本中

编辑一个gauge.sh 的脚本

内容如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

#!/bin/bash

# vim gauge.sh

declare

-

i

PERCENT

=

0

(

for

I

in

/

etc

/

*

;

do

if

[

$

PERCENT

-

le

100

]

;

then

cp

-

r

$

I

/

tmp

/

test

2

>

/

dev

/

null

echo

"XXX"

echo

"Copy the file $I ..."

echo

"XXX"

echo

$

PERCENT

fi

let

PERCENT

+=

1

sleep

0.1

done

)

|

dialog

--

title

"coping"

--

gauge

"starting to copy files..."

6

50

0

#bash  gauge.sh  (执行脚本的时候注意修改权限)

0818b9ca8b590ca3270a3433284dd417.png

11.from框架(表单)

格式:dialog --form text height width formheight [ label y x item y x flen ilen ] ...

其中

flen 表示field length,定义了:选定字段中显示的长度

ilen 表示 input-length, 定义了:在外地输入的数据允许的长度

使用up/down(或ctrl/ N,ctrl/ P)在使用领域之间移动。使用tab键在窗口之间切换。

例子:

# dialog --title "Add a user" --form "Please input the infomation of new user:" 12 40 4  \

"Username:" 1  1 "" 1  15  15  0  \

"Full name:" 2  1 "" 2  15  15  0  \

"Home Dir:" 3  1 "" 3  15  15  0  \

"Shell:"    4   1 "" 4  15  15  0

0818b9ca8b590ca3270a3433284dd417.png

综合应用示例:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

#!/bin/bash

yesno

(

)

{

dialog

--

title

"First screen"

--

backtitle

"Test Program"

--

clear

--

yesno

\

"Start this test program or not ? \nThis decesion have to make by you. "

16

51

# yes is 0, no is 1 , esc is 255

result

=

$

?

if

[

$

result

-

eq

1

]

;

then

exit

1

;

elif

[

$

result

-

eq

255

]

;

then

exit

255

;

fi

username

}

username

(

)

{

cat

/

dev

/

null

>

/

tmp

/

test

.

username

dialog

--

title

"Second screen"

--

backtitle

"Test Program"

--

clear

--

inputbox

\

"Please input your username (default: hello) "

16

51

"hello"

2

>

/

tmp

/

test

.

username

result

=

$

?

if

[

$

result

-

eq

1

]

;

then

yesno

elif

[

$

result

-

eq

255

]

;

then

exit

255

;

fi

password

}

password

(

)

{

cat

/

dev

/

null

>

/

tmp

/

test

.

password

dialog

--

insecure

--

title

"Third screen"

--

backtitle

"Test Program"

--

clear

--

passwordbox

\

"Please input your password (default: 123456) "

16

51

"123456"

2

>

/

tmp

/

test

.

password

result

=

$

?

if

[

$

result

-

eq

1

]

;

then

username

elif

[

$

result

-

eq

255

]

;

then

exit

255

;

fi

occupation

}

occupation

(

)

{

cat

/

dev

/

null

>

/

tmp

/

test

.

occupation

dialog

--

title

"Forth screen"

--

backtitle

"Test Program"

--

clear

--

menu

\

"Please choose your occupation: (default: IT)"

16

51

3

\

IT

"The worst occupation"

\

CEO

"The best occupation"

\

Teacher

"Not the best or worst"

2

>

/

tmp

/

test

.

occupation

result

=

$

?

if

[

$

result

-

eq

1

]

;

then

password

elif

[

$

result

-

eq

255

]

;

then

exit

255

;

fi

finish

}

finish

(

)

{

dialog

--

title

"Fifth screen"

--

backtitle

"Test Program"

--

clear

--

msgbox

\

"Congratulations! The test program has finished!\n Username: $(cat /tmp/test.username)\n Password: $(cat /tmp/test.password)\n Occupation: $(cat /tmp/test.occupation)"

16

51

result

=

$

?

if

[

$

result

-

eq

1

]

;

then

occupation

elif

[

$

result

-

eq

255

]

;

then

exit

255

;

fi

}

yesno

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

0818b9ca8b590ca3270a3433284dd417.png

本文转自:http://gdcsy.blog.163.com/blog/static/1273436092013016069255/

本站整理:http://www.ttlsa.com/html/3085.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值