Termux-api之termux-dialog

官方的命令讲解

1
2
3
4
5
6
7
Usage: 
    termux-dialog widget [options] 
    Get user input w/ different widgets! 
    Default: text 
        -h, help Show this help 
        -l, list List all widgets and their options 
        -t, title Set title of input dialog (optional)

翻译后

1
2
3
4
5
6
7
#使用:
    termux-dialog widget [options]
    #获取用户输入的widget或者不同的widget
    #默认:文本
        -h, #展示这条帮助信息
        -l, #列出所有的widget和它们对应的options
        -t, #设置dialog的标题(非必须)

termux-dialog -l 讲解

 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
Supported widgets: 
    confirm - Show confirmation dialog #显示确认信息
        [-i hint] text hint (optional) #需要提示的回答的文字
        [-t title] set title of dialog (optional) 
    checkbox - Select multiple values using checkboxes #使用复选框选择多个值
        [-v ",,,"] comma delim values to use (required) #使用逗号间隔
        [-t title] set title of dialog (optional) 
    counter - Pick a number in specified range #选择指定范围内的数字
        [-r min,max,start] comma delim of (3) numbers to use (optional) #使用3个数字确定范围
        [-t title] set title of dialog (optional) 
    date - Pick a date #选择一个日期
        [-t title] set title of dialog (optional) 
        [-d "dd-MM-yyyy kⓜ️s"] SimpleDateFormat Pattern for date widget output (optional) #设置输出格式
    radio - Pick a single value from radio buttons #从单选按钮中选择一个值
        [-v ",,,"] comma delim values to use (required) #使用逗号间隔
        [-t title] set title of dialog (optional) 
    sheet - Pick a value from sliding bottom sheet #从滑动底部表中选择一个值
    	[-v ",,,"] comma delim values to use (required) #使用逗号间隔
    	[-t title] set title of dialog (optional) 
    spinner - Pick a single value from a dropdown spinner #从下拉菜单中选择一个值
    	[-v ",,,"] comma delim values to use (required) 
    	[-t title] set title of dialog (optional) 
    speech - Obtain speech using device microphone #使用设备麦克风获取语音(可理解为文字转语音)
    	[-i hint] text hint (optional) #设置提示的文字
    	[-t title] set title of dialog (optional) 
    text - Input text (default if no widget specified) #输入文本
    	[-i hint] text hint (optional) #需要提示的文字
    	[-m] multiple lines instead of single (optional)* #多行文本内容 
    	[-n] enter input as numbers (optional)* #输入类型为数字
    	[-p] enter input as password (optional) #输入类型为密码
    	[-t title] set title of dialog (optional)  

示例:

1.confirm
1
termux-dialog confirm -i "Choose Yes or No" -t "Do you copy?"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog1.bmp

1
2
3
4
5
6
//选择yes
{
  "code": 0,
  "text": "yes",
  "index": 2
}
1
2
3
4
5
6
//选择no
{
  "code": 0,
  "text": "no",
  "index": 2
}
2.checkbox
1
termux-dialog checkbox -v "草莓,菠萝,香蕉,榴莲" -t "你喜欢吃哪些水果?"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/trmux-dialog2.bmp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
//仅选择香蕉
{
  "code": -1,
  "text": "[香蕉]",
  "index": 2,
  "values": [
    {
      "index": 2,
      "text": "香蕉"
    }
  ]
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//选择全部
{
  "code": -1,
  "text": "[草莓, 菠萝, 香蕉, 榴莲]",
  "index": 2,
  "values": [
    {
      "index": 0,
      "text": "草莓"
    },
    {
      "index": 1,
      "text": "菠萝"
    },
    {
      "index": 2,
      "text": "香蕉"
    },
    {
      "index": 3,
      "text": "榴莲"
    }
  ]
}
3.counter
1
termux-dialog counter -r 1,120,18 -t "How old are you?"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog3.bmp

1
2
3
4
5
6
//选择19
{
  "code": -1,
  "text": "19",
  "index": 2
}
4.date
1
termux-dialog date -t "2020年国庆日期:" -d "yyyy-MM-dd"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog4.bmp

1
2
3
4
5
6
//日期选择为2020101
{
  "code": -1,
  "text": "2020-10-01",
  "index": 2
}
5.radio
1
termux-dialog radio -v "男生,女生" -t "你喜欢男生还是女生?"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog5.bmp

1
2
3
4
5
6
//选择女生
{
  "code": -1,
  "text": "女生",
  "index": 1
}
6.sheet
1
termux-dialog sheet -v "月球,地球,火星" -t "你来自哪里?"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog6.bmp

1
2
3
4
5
6
//选择地球
{
  "code": 0,
  "text": "地球",
  "index": 1
}
7.spinner
1
termux-dialog spinner -v "语文,综合,英语,数学" -t "高考第三门考什么?"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog7.bmp

1
2
3
4
5
6
//选择综合
{
  "code": -1,
  "text": "综合",
  "index": 1
}
8.speech
1
termux-dialog speech -i "你叫什么名字呀?" -t "What is your name?"

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog8.bmp

1
2
3
4
5
6
{
  "code": 0,
  "text": "布里啾啾底部里都", 
  "index": 1
}

9.text
1
termux-dialog text -i "你的qq号码:" -t "提示信息" -n

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog91.jpg

1
2
3
4
5
6
//输入我的qq号
{
  "code": -1,
  "text": "1053651085",
  "index": 1
}
1
termux-dialog text -i "你的qq密码:" -t "提示信息" -p

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog92.jpg

1
2
3
4
5
{
  "code": -1,
  "text": "shazicaihuiqushi",
  "index": 1
}
1
termux-dialog text -i "写一篇10亿字的读后感:" -t "提示信息" -m

https://gitee.com//Brief-rf/BlogImages/raw/master/img/termux-dialog93.jpg

1
2
3
4
5
{
  "code": -1,
  "text": "你\n在\n想\n屁\n吃",
  "index": 1
}

提取文本内容

如果你不用jq来提取json字符转中text后面的内容,那么下面的一串代码将会帮助到你

1
2
3
#适用于大多情况
#弹出对话框,并将对话框的内容作为shell命令执行
termux-dialog -t "Enter shell command"|awk -F'"' '$2=/text/{print $4}'|bash