dialog<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1.dialogLinux中用来实现模拟小窗口

语法格式如下:

dialog --common-options --boxtype "Text" Height Width --box-specific-option

--common-option选项是用来设置dialog背景色、标题、等

--boxtype用来指定dialog参数的,dialog至少有三个参数:

Text标题或内容,

height高度,

width宽度

另外还有--begin y x用来指定一个dialogbox位置在这个屏幕上显示的坐标位

--colors给“\Z”和“\Zn” 添加颜色的之间的内容添加颜色的

--defaultno代表yes/no的默认值

--default-item string设置box的默认项时前边的是默认项

--insecure设置窗口密码但不安全,通常以“*”号显示出来

--timeout指定一个超时时间

--nook隐藏ok按钮选项框

--no-shadow去掉阴影

--ok-label string重读ok按钮标签

1)例:dialog --backtitle “The first dialog box”  --title “Hello” --yesno “Is this your first dialog box?” 10 30

--backtitle表示背景显示的标题

--title表使box的标题

--yesno表示所选框

10表示box的高度

30表示box的宽度

显示如下图

box选项如下图:

widget窗口元素,窗口类型具体描述如下图

dialog --msgbox text height width形式:

2)例dialog --title Testing --colors --msgbox “Z3This is a testZn” 5 1 30 2>dialog.out

--msgbox显示一段信息或要求后用户只能去选择“ok”按钮了

显示如下图所示:

  

3)看到“This is a test“已经变红色了

dialog --yesno text height width形式:

dialog --title “Delete a file”  --no-shadow --yesno “Delete the file /tmp/test.txt?” 10 30显示如下图:

可看到阴影已消失了

4) dialog --inputbox text height width形式

dialog --title “Input your name”  --inputbox “Please input your name:” 10 30  2> /tmp/name.txt

  其中2> 清空/tmp/name.txt文件的内容,并保存标准错误输出的内容到指/tmp/name.txt

 --inputbox表输入文本

显示如下图所示

5dialog --textbox file height width形式:

dialog --title “The fstab” --textbox /etc/fstab  16 60用文本形式输出/etc/fstab的信息,显示具体如图:

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

dialog --title “pick a choice” --menu “Choose one” 12 35 5 1 “Display the disk usage” 2 “Display the meminfo” 3 “Exit”

 --menu用来指定按钮选项的

 如下图

 看到出现了123三个选择

7dialog --fselect filepath height width 形式:

dialog --title “Pick one file” --fselect /root/ 8 40

如下图:

8dialog --gauge text height width  [<percent>]

  --gause用来指定文件的传输情况的

例:Vim  gauge.sh

  #!/bin/bash

#

let PERCENT=0                      ##let定义一个整数变量

(

for I in /etc/*                         ##for-do-done循环语句 

do

  if [ $PERCENT -gt 100 ];then          ##if-then-else循环语句,如果大于100则跳出循环

     break

  else

     cp -r $I /tmp/test 2> /dev/null         ##否则就递归复制/etc/*到文件/tmp/test/中并将错误信息放到/dev/null

     echo 'XXX'                              ##用来显示即将复制文件名的

     echo "copy the file $I..."

     echo 'XXX'

     echo $PERCENT                          

   fi

   PERCENT=$[ $PERCENT+1 ]              

   sleep 1                                  ##每复制一次歇一秒

done ) | dialog --title "Copying..." --gauge "Starting to copy files..." 6 60 0

~

bash gauge.sh(执行)

结果如图下所示   

  

Vim  gauge2.sh

 #!/bin/bash

#

let PERCENT=0

let I=1

(

while [ $I -le 254 ]; do

  echo "XXX"

  if  ping -c1 -w1 192.168.0.$I &> /dev/null ;then   ##每一秒ping一个地址

    echo "Ha, 192.168.0.${I} is online."            ##如果成功则显此信息示

  else

    echo -e "Sorry, 192.168.0.$I is not online."        ##否则显示不在线

  fi

  echo "XXX"

  let "I++"

  let "PERCENT=100*$I/254"              ##100的百分比分成

  echo $PERCENT                         254份,当$I为值时对应的百分比为$PERCENT

  #sleep 1

done ) | dialog --title "Pinging..." --gauge "Start to ping..." 7 60 0 

bash  -n  gauge.sh(检查语法是否正确)

bash  gauge2.sh  (用bash执行)

显示如下图:

                      

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

   --form插入表单

   flen 定义输出显示时的区域的宽度

   ilen定义数据可输入的宽度

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  

如图:

 

 10dialog  --passwordbox text height width [init]

--insecure 形式

--passwordbox为用户添加密码(默认用“*”来显示输入的值

dialog  --passwordbox text 10 20

    如下图