摘要:下的是一个可以创建对话框的工具,每个对话框提供的输出有两种形式将所有输出到,不显示到屏幕使用退出状态码,为,为,为。设置在输入框菜单和复选框中不显示项。在带有滚动条的文本框中显示文件的内容文本框。
Liunx下的dialog是一个可以创建对话框的工具,每个对话框提供的输出有两种形式:1、将所有输出到stderr,不显示到屏幕;2、使用退出状态码,OK为0,NO为1,ESC为255。
通用选项(common options)这个选项用来设置dialog box的背景、颜色和标题等。
--title
--colors:解读嵌入式 Z的对话框中的特殊文本序列,序列由下面的字符0-7, b,B, u, U等组成,恢复正常的设置使用n。
--no-shadow:禁止阴影出现在每个对话框的底部。
--shadow:出现阴影效果。
--insecure:输入部件的密码时,使用星号来代表每个字符。
--no-cancel:设置在输入框、菜单和复选框中不显示cancel项。
--clear:完成清屏操作,在框体显示结束后,清除框体,这个参数只能多带带使用,不能和别的参数联合使用。
--ok-label
--cancel-label
--backtitle
--begin
--timeout
--defaultno:使的是默认值yes/no,使用no。
--sleep
--stderr:以标准错误方式输出。
--stdout:以标准方式输出。
--default-item
常见的对话框控件选项如下所示:
--calendar:提供了一个日历,让你可以选择日期。
--checklist:允许你显示一个选项列表,每个选项都可以被多带带的选择(复选框)。
--from:允许建立一个带标签的文本字段,并要求填写。
--fselect:提供一个路径,让你选择浏览的文件。
--gauge:显示一个表,呈现出完成的百分比,就是显示出进度。
--infobox:显示消息后,(没有等待响应)对话框立刻返回,但不清除屏幕(信息框)。
--inputbox:让用户输入文本(输入框)。
--inputmenu:提供一个可供用户编辑的菜单(可编辑的菜单框)。
--menu:显示一个列表供用户选择(菜单框)。
--msgbox:显示一条消息,并要求用户选择一个确定按钮(消息框)。
--pause:显示一个表格用来显示一个指定的暂停期的状态。
--passwordbox:显示一个输入框,它隐藏文本。
--passwordfrom:显示一个来源于标签并且隐藏的文本字段。
--radiolist:提供一个菜单项目组,只有一个项目,可以选择(单选框)。
--tailbox:在一个滚动窗口文件中使用tail命令来显示文本。
--tailboxbg:跟tailbox类似,但是在background模式下操作。
--textbox:在带有滚动条的文本框中显示文件的内容(文本框)。
--timebox:提供一个窗口,选择小时、分钟、秒。
--yesno:提供一个带有yes和no按钮的简单信息框(是/否框)。
格式:
dialog --msgbox text height width
例子:
$ dialog --title TESTING --msgbox "this is a test" 10 20yesno框
格式:
dialog --yesno text height width
例子:
$ dialog --title "yes/no" --no-shadow --yesno "Delete the file /tmp/canjian.txt?" 10 30输入框
格式:
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文件中。
密码框格式:
dialog --passwordbox text height width [init]
例子:
$ dialog --title "Password" --passwordbox "Please give a password for the new user:" 10 35
密码暴露出来不安全,所以通常我们会加上一个安全选项--insecure,将每个字符用*来显示。
$ dialog --title "Password" --insecure --passwordbox "Please give a password for the new user:" 10 30文本框
格式:
dialog --textbox file height width
例子:
$ dialog --title "The fstab" --textbox /etc/fstab 17 40菜单框
格式:
dialog --menu text height width menu-height tag1 item1 tag2 item2 …
例子:
$ dialog --title "Pick a choice" --menu "Choose one" 12 35 5 1 "say hello to everyone" 2 "thanks for your support" 3 "exit"Fselect框(文件选框)
格式:
dialog --fselect filepath height width
例子:
$ dialog --title "Pick one file" --fselect /root/ 7 40复选框
格式:
dialog --checklist "Test" height width menu-height tag1 item1 tag2 item2 …
例子:
$ dialog --backtitle "Checklist" --checklist "Test" 20 50 10 Memory Memory_Size 1 Dsik Disk_Size 2显示日历
格式:
dialog --calendar "Date" height width day month year
例子:
显示当前日期
$ dialog --title "Calendar" --calendar "Date" 5 50
显示指定日期
$ dialog --title "Calendar" --calendar "Date" 5 50 1 2 2013进度框架
格式:
dialog --gauge text height width []
例子:
固定进度显示
$ dialog --title "installation pro" --gauge "installation" 10 30 10
实时动度进度
$ for i in {1..100} ;do echo $i;done | dialog --title "installation pro" --gauge "installation" 10 30
编辑一个gauge.sh的脚本,内容如下:
#!/bin/bash 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 0from框架(表单)
格式:
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综合应用示例
#! /bin/bash yesno() { dialog --title "First screen" --backtitle "Test Program" --clear --yesno "Start this test program or not ? This 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! Username: $(cat /tmp/test.username) Password: $(cat /tmp/test.password) Occupation: $(cat /tmp/test.occupation)" 16 51 result=$? if [ $result -eq 1 ] ; then occupation elif [ $result -eq 255 ]; then exit 255; fi } yesno;
Linux下的dialog工具使用方法
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/9049.html
摘要:下的是一个可以创建对话框的工具,每个对话框提供的输出有两种形式将所有输出到,不显示到屏幕使用退出状态码,为,为,为。设置在输入框菜单和复选框中不显示项。在带有滚动条的文本框中显示文件的内容文本框。 Liunx下的dialog是一个可以创建对话框的工具,每个对话框提供的输出有两种形式:1、将所有输出到stderr,不显示到屏幕;2、使用退出状态码,OK为0,NO为1,ESC为255。 ...
摘要:命令行与脚本编程大全第三版第十八章学习总结第十八章图形化桌面环境中的脚本编程本章内容创建文本菜单创建文本窗口部件添加图形创建文本菜单创建交互式脚本最常用的方法是使用菜单,脚本菜单的核心是命令,命令会根据用户在菜单上的选择来执行特定命令。 时间:2017年12月04日星期一说明:本文部分内容均摘取自书籍《Linux命令行与shell脚本编程大全》,版权归原作者所有。《Linux命令行与s...
摘要:将程序包装在界面里,可以将输入通过多种途径如文本框弹出路径选择等输入到程序里。将输出通过文本框显示出来将执行信息如如报错信息运行进度通过文本框或进度条显示出来文章安排先介绍安装和配合的使用。 作为一个程序的开发者,我们仅仅需要在相应路径通过命令行就可执行那个程序。但是,不懂行的人不理解这个黑框框的东西,陌生领域任何人都没有安全感,所以他们是拒绝接受一个项目仅仅只是通过一个黑框框来执行的...
摘要:终端窗口与虚拟控制台大部分终端模拟器都是在图形用户界面中运行的,但是也有例外。不过不要被它们唬着了,虽然它们并不运行在图形界面中,但其实它们也是终端模拟器的一种。 原文发表在我的 博客 上,欢迎订阅。;) 为什么突然想写这样一篇文章呢?其实是因为在最近计划发布的一篇关于 WSL (Windows Subsystem for Linux) 的博文中,我打算对终端模拟器、Shell 的选择...
摘要:控制台终端进入的一种方式是让系统退出图形化桌面模式,进入文本模式。它们分别是和,通常都会默认安装在发行版中。命令行参数的命令行参数非常多。小结为了着手学习命令行,得先能访问命令行。 时间:2017年04月05日 说明:本文部分内容均摘取自书籍《Linux命令行与shell脚本编程大全》,版权归原作者所有。《Linux命令行与shell脚本编程大全》(第三版)第二章学习总结 第二章:走进...
阅读 2113·2021-11-12 10:34
阅读 1350·2019-08-29 16:15
阅读 2571·2019-08-29 15:17
阅读 1108·2019-08-23 17:09
阅读 255·2019-08-23 11:37
阅读 2327·2019-08-23 10:39
阅读 348·2019-08-22 16:43
阅读 3002·2019-08-22 14:53