注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

独木人生

感悟生命

 
 
 

日志

 
 

dialog使用笔记(2)  

2007-08-19 16:06:05|  分类: Linux |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
在笔记(1)中给出了dialog的一些简单介绍。下面来学习和分析dialog(未说明皆是cdialog)的samples。

1、calender参数说明

参数如下:

--calendar     <text> <height> <width> <day> <month> <year>

man中说明为:

       --calendar text height width day month year
              A calendar box displays month, day and year in separately adjustable  windows.   If
              the  values for day, month or year are missing or negative, the current date's cor-
              responding values are used.  You can increment or decrement any of those using  the
              left-,  up-,  right- and down-arrows.  Use vi-style h, j, k and l for moving around
              the array of days in a month.  Use tab or backtab to move between windows.  If  the
              year is given as zero, the current date is used as an initial value.

              On exit, the date is printed in the form day/month/year.

2 、samples::calender源码

#!/bin/sh
# $Id: calendar,v 1.4 2003/10/09 22:45:06 tom Exp $
: ${DIALOG=dialog}

exec 3>&1
USERDATE=`$DIALOG --title "CALENDAR" --calendar "Please choose a date..." 0 0 7 7 1981 2>&1 1>&3`
code=$?
exec 3>&-

case $code in
  0)
    echo "Date entered: $USERDATE.";;
  1)
    echo "Cancel pressed.";;
  255)
    echo "Box closed.";;
esac

效果如图所示:



3、源码解析

: ${DIALOG=dialog} --- 相当于DIALOG=dialog,设置DIALOG变量。":"命令相当于"ture",不起作用。

exec 3>&1 --- I/O重定向,"1"为标准输出,即stdout。这里将FD3(File Descriptor 3)与stdout流合并。

USERDATE=`$DIALOG --title "CALENDAR" --calendar "Please choose a date..." 0 0 7 7 1981 2>&1 1>&3` --- 执行dialog命令,合并输出流,将结果赋值USERDATE

code=$? ---  将dialog命令的返回值复制CODE

exec 3>&- ---  关闭FD3

其余是根据$CODE的值,输出提示。255表示退出,按两次ESC。

ps: 脚本中的I/O重定向可以用选项--stdout代替。

man中的说明:

       --stdout
              Direct output to the standard output.  This option is  provided  for  compatibility
              with Xdialog, however using it in portable scripts is not recommended, since curses
              normally writes its screen updates to the standard output.  If you use this option,
              dialog  attempts  to reopen the terminal so it can write to the display.  Depending
              on the platform and your environment, that may fail.

4、进阶--添加button

# calender3
#!/bin/sh
# $Id: calendar3,v 1.4 2003/10/09 22:45:06 tom Exp $
: ${DIALOG=dialog}

exec 3>&1
USERDATE=`$DIALOG --extra-button --extra-label "Hold" --help-button --title "CALENDAR" --calendar "Please choose a date..." 0 0 7 7 1981 2>&1 1>&3`
code=$?
exec 3>&-

case $code in
  0)
    echo "Date entered: $USERDATE.";;
  1)
    echo "Cancel pressed.";;
  2)
    echo "Help pressed.";;
  3)
    echo "Hold pressed.";;
  255)
    echo "Box closed.";;
esac

这里与原来基本一致,只是添加了两个基本button:"hold" 和 "help"。

man中介绍:

       --extra-button
              Show an extra button, between "OK" and "Cancel" buttons.
       --extra-label string
              Override the label used for "Extra" buttons.  Note: for inputmenu widgets, this de-
              faults to "Rename".
       --help-button
              Show a help-button after "OK" and "Cancel" buttons, i.e., in  checklist,  radiolist
              and  menu boxes.  If "--item-help" is also given, on exit the return status will be
              the same as for the "OK" button, and the item-help text will be written to dialog's
              output after the token "HELP".  Otherwise, the return status will indicate that the
              Help button was pressed, and no message printed.


各button对应的$code如下:

OK       ---> 0
Cancel  ---> 1
Help     ---> 2
Hold     ---> 3
ESC     ---> 255


  评论这张
 
阅读(223)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017