From 65ce53b8afe0176bcd088ae1c3e5bad53fe91883 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Sun, 27 May 2018 17:20:26 -0600 Subject: [PATCH 01/10] WIP termux-dialog script to use new additional API options --- scripts/termux-dialog | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 1932401..d196eff 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -3,12 +3,14 @@ set -e -u SCRIPTNAME=termux-dialog show_usage () { - echo "Usage: $SCRIPTNAME [-i hint] [-m] [-p] [-t title]" + echo "Usage: $SCRIPTNAME [-i hint] [-m] [-p] [-t title] [-w widget]" echo "Show a text entry dialog." - echo " -i hint the input hint to show when the input is empty" - echo " -m use a textarea with multiple lines instead of a single" - echo " -p enter the input as a password" - echo " -t title the title to show for the input prompt" + echo " -i hint the input hint to show when the input is empty" + echo " -m use a textarea with multiple lines instead of a single" + echo " -p enter the input as a password" + echo " -t title the title to show for the input prompt" + echo " -w widget widget type to use: confirm, text, date, time, spinner, or speech" + echo " -v values [,,,] values to use w/ spinner widget" exit 0 } @@ -20,8 +22,14 @@ ARG_M="" ARG_P="" ARG_T="" OPT_T="" +OPT_V="" +ARG_V="" -while getopts :hi:mpt: option +# Use default values to preserve backwards compatibility w/ older dialog implementation +OPT_W="text" +ARG_W="--es input_method" + +while getopts :hi:mpt:v:w: option do case "$option" in h) show_usage;; @@ -29,15 +37,19 @@ do m) ARG_M="--ez multiple_lines true";; p) ARG_P="--es input_type password";; t) ARG_T="--es input_title"; OPT_T="$OPTARG";; + w) ARG_W="--es input_method"; OPT_W="$OPTARG";; + v) ARG_V="--es input_values"; OPT_V="$OPTARG";; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done shift $(($OPTIND-1)) -if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi +# if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi set -- $ARG_M $ARG_P if [ -n "$ARG_I" ]; then set -- "$@" $ARG_I "$OPT_I"; fi if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi +if [ -n "$ARG_V" ]; then set -- "$@" $ARG_V "$OPT_V"; fi +if [ -n "$ARG_W" ]; then set -- "$@" $ARG_W "$OPT_W"; fi /data/data/com.termux/files/usr/libexec/termux-api Dialog "$@" From 82542a6d1ad317a40f7aa54e37109d0e9a39aea4 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Tue, 19 Jun 2018 22:07:58 -0600 Subject: [PATCH 02/10] Implements all new widgets and adds extensive error checking --- scripts/termux-dialog | 263 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 231 insertions(+), 32 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index d196eff..665fba6 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -1,55 +1,254 @@ -#!/data/data/com.termux/files/usr/bin/sh +#!/data/data/com.termux/files/usr/bin/bash set -e -u +DEFAULT_WIDGET="text" + SCRIPTNAME=termux-dialog -show_usage () { - echo "Usage: $SCRIPTNAME [-i hint] [-m] [-p] [-t title] [-w widget]" - echo "Show a text entry dialog." - echo " -i hint the input hint to show when the input is empty" - echo " -m use a textarea with multiple lines instead of a single" - echo " -p enter the input as a password" - echo " -t title the title to show for the input prompt" - echo " -w widget widget type to use: confirm, text, date, time, spinner, or speech" - echo " -v values [,,,] values to use w/ spinner widget" +show_usage() { + echo "Usage: $SCRIPTNAME widget [options]" + echo "Get user input w/ different widgets! Default Widget: $DEFAULT_WIDGET" + echo " -h, help Show this help" + echo " -l, list Full list all available widgets and their options" + echo " -t, title Set title of input dialog" exit 0 } -PARAMS="" +declare -a widgets=("confirm" "checkbox" "counter" "date" "radio" "sheet" "spinner" "text" "time") + +# Descriptions for various options that multiple widgets can use +OPT_HINT_DESC="[-i hint] text hint (optional)" +OPT_MULTI_LINE_DESC="[-m multi-line] use a textarea with multiple lines instead of single (optional)" +OPT_PASS_DESC="[-p password] enter input as password (optional)" +OPT_TITLE_DESC="[-t title] dialog title (optional)" +OPT_RANGE_DESC="[-r range] min,max,start where each value is a number (optional)" +OPT_VALUES_DESC="[-v values] comma delimited string of values to use (required)" +# Widget hints ARG_I="" OPT_I="" + +# Text widget multiline ARG_M="" + +# Counter range +ARG_R="" +OPT_R="" + +# Text widget input as password ARG_P="" + +# Dialog title (supported by all widgets) ARG_T="" OPT_T="" + +# Values for list-type widgets OPT_V="" ARG_V="" -# Use default values to preserve backwards compatibility w/ older dialog implementation -OPT_W="text" +# Widget type +ARG_W="" +WIDGET="" + +# Flags for detecting invalid option combinations +HINT_FLAG=1 +MULTI_LINE_FLAG=2 +PASS_FLAG=4 +RANGE_FLAG=8 +VALUES_FLAG=16 + +FLAGS=0 + + +# Show usage help for specific widget +widget_usage () { + echo -n -e "$1 \t" + + case "$1" in + "confirm") + echo -e "Show confirmation dialog" + echo -e "\t\t$OPT_TITLE_DESC" + echo -e "\t\t$OPT_HINT_DESC" + ;; + "checkbox") + echo -e "Select multiple values using checkboxes" + echo -e "\t\t$OPT_VALUES_DESC" + echo -e "\t\t$OPT_TITLE_DESC" + ;; + "counter") + echo -e "Pick a number in specified range" + echo -e "\t\t$OPT_TITLE_DESC" + echo -e "\t\t$OPT_RANGE_DESC" + ;; + "date") + echo -e "\tPick a date" + echo -e "\t\t$OPT_TITLE_DESC" + ;; + "radio") + echo -e "\tPick a single value from radio buttons" + echo -e "\t\t$OPT_VALUES_DESC" + echo -e "\t\t$OPT_TITLE_DESC" + ;; + "sheet") + echo -e "\tPick a value from a sliding bottom sheet interface" + echo -e "\t\t$OPT_VALUES_DESC" + echo -e "\t\t$OPT_TITLE_DESC" + ;; + "spinner") + echo -e "Pick a single value from a dropdown spinner" + echo -e "\t\t$OPT_VALUES_DESC" + echo -e "\t\t$OPT_TITLE_DESC" + ;; + "text") + echo -e "\tInput text (default if no widget specified)" + echo -e "\t\t$OPT_HINT_DESC" + echo -e "\t\t$OPT_PASS_DESC -- cannot use with -m" + echo -e "\t\t$OPT_TITLE_DESC" + echo -e "\t\t$OPT_MULTI_LINE_DESC -- cannot use with -p" + ;; + "time") + echo -e "\tPick a time value" + echo -e "\t\t[-p title] dialog title (optional)" + ;; + *) + echo -e "\tUnknown usage for '$1'" + ;; + esac +} + +# List all widgets +list_widgets() { + echo "Supported widgets:" + echo + + for w in "${widgets[@]}"; do + widget_usage $w + echo + done +} + +# Checks to see if widgets array contains specified widget +has_widget () { + for w in "${widgets[@]}"; do + [ "$w" == "$1" ] && return 0 + done + return 1 +} + +set_flag () { + FLAGS=$((FLAGS | $1)); +} + +# Convenience method to get all supported options, regardless of specified widget +# NOTE: Option combination validation doesn't occur here +parse_options() { + while getopts :hlmpr:i:t:v: option + do + case "$option" in + h) show_usage ;; + l) list_widgets; exit 0;; + i) ARG_I="--es input_hint"; OPT_I="$OPTARG"; set_flag $HINT_FLAG; ;; + m) ARG_M="--ez multiple_lines true"; set_flag $MULTI_LINE_FLAG; ;; + p) ARG_P="--es input_type password"; set_flag $PASS_FLAG; ;; + t) ARG_T="--es input_title"; OPT_T="$OPTARG" ;; + v) ARG_V="--es input_values"; OPT_V="$OPTARG"; set_flag $VALUES_FLAG; ;; + r) ARG_R="--eia input_range"; OPT_R=$OPTARG; set_flag $RANGE_FLAG; ;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac + done +} + +options_error () { + echo -e "ERROR: Invalid option(s) detected for '$1'\n" + echo "Usage '$1'" + widget_usage $1 + exit 1 +} + +if [ $# -eq 0 ]; then + WIDGET=$DEFAULT_WIDGET +# First argument wasn't a widget +elif ! has_widget $1; then + # we didn't receive a widget as an argument, check to see if we + # at least options (even if they're illegal) + if ! [[ $1 =~ -[a-z] ]]; then + echo -e "ERROR: Illegal argument $1\n" + show_usage + fi + WIDGET=$DEFAULT_WIDGET +else + WIDGET=$1 + shift +fi + +parse_options "$@" +shift $((OPTIND - 1)) + +# Ensure proper option combinations for the specific type of widget +case "$WIDGET" in + # Text (default) if no widget specified + "text") + if [ $((FLAGS & (RANGE_FLAG | VALUES_FLAG))) -ne 0 ]; then + options_error $WIDGET + fi + + if [ $((FLAGS & MULTI_LINE_FLAG)) -ne 0 ] && [ $((FLAGS & PASS_FLAG)) -ne 0 ]; then + options_error $WIDGET + fi + ;; + + "confirm") + if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG))) -ne 0 ]; then + options_error $WIDGET + fi + ;; + + "counter") + if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | VALUES_FLAG))) -ne 0 ]; then + options_error $WIDGET + fi + ;; + + "date" | "speech" | "time") + if [ $# -gt 0 ]; then + echo "ERROR: '$WIDGET' takes no arguments"; exit 1; + fi + + if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG))) -ne 0 ]; then + options_error $WIDGET + fi + ;; + + "checkbox" | "radio" | "sheet" | "spinner") + if [ "$ARG_V" == "" ]; then + echo "ERROR: '$WIDGET' must be called with $OPT_VALUES_DESC" + exit 1 + fi + + if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG))) -ne 0 ]; then + options_error $WIDGET + fi + ;; + + *) + echo "$SCRIPTNAME: unsupported widget '$WIDGET'"; show_usage ;; +esac + +# All valid args should be consumed by this point +if [ $# -gt 0 ]; then + echo "ERROR: Too many arguments!" + show_usage +fi + ARG_W="--es input_method" -while getopts :hi:mpt:v:w: option -do - case "$option" in - h) show_usage;; - i) ARG_I="--es input_hint"; OPT_I="$OPTARG";; - m) ARG_M="--ez multiple_lines true";; - p) ARG_P="--es input_type password";; - t) ARG_T="--es input_title"; OPT_T="$OPTARG";; - w) ARG_W="--es input_method"; OPT_W="$OPTARG";; - v) ARG_V="--es input_values"; OPT_V="$OPTARG";; - ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; - esac -done -shift $(($OPTIND-1)) - -# if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi - -set -- $ARG_M $ARG_P +# Set options, ensuring whitespace isn't lost +if [ -n "$ARG_W" ]; then set -- "$@" $ARG_W "$WIDGET"; fi if [ -n "$ARG_I" ]; then set -- "$@" $ARG_I "$OPT_I"; fi if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi +if [ -n "$ARG_R" ]; then set -- "$@" $ARG_R "$OPT_R"; fi if [ -n "$ARG_V" ]; then set -- "$@" $ARG_V "$OPT_V"; fi -if [ -n "$ARG_W" ]; then set -- "$@" $ARG_W "$OPT_W"; fi +if [ -n "$ARG_M" ]; then set -- "$@" $ARG_M ""; fi +if [ -n "$ARG_P" ]; then set -- "$@" $ARG_P ""; fi + /data/data/com.termux/files/usr/libexec/termux-api Dialog "$@" From ed220b1048b0bf0cfe725e035be5ecaa3c28a9a8 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 11:23:12 -0600 Subject: [PATCH 03/10] Fix widget arg not doing anything --- scripts/termux-dialog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 665fba6..b4c425a 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -174,9 +174,9 @@ elif ! has_widget $1; then echo -e "ERROR: Illegal argument $1\n" show_usage fi - WIDGET=$DEFAULT_WIDGET + WIDGET="$DEFAULT_WIDGET" else - WIDGET=$1 + WIDGET="$1" shift fi From 2a5bc2cd883ceb46842166017db4a933eeabbb35 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 13:51:26 -0600 Subject: [PATCH 04/10] Reduce indentation in widget listing --- scripts/termux-dialog | 58 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index b4c425a..7249871 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -61,56 +61,56 @@ FLAGS=0 # Show usage help for specific widget widget_usage () { - echo -n -e "$1 \t" + echo -n -e "$1 - " case "$1" in "confirm") - echo -e "Show confirmation dialog" - echo -e "\t\t$OPT_TITLE_DESC" - echo -e "\t\t$OPT_HINT_DESC" + echo "Show confirmation dialog" + echo " $OPT_TITLE_DESC" + echo " $OPT_HINT_DESC" ;; "checkbox") - echo -e "Select multiple values using checkboxes" - echo -e "\t\t$OPT_VALUES_DESC" - echo -e "\t\t$OPT_TITLE_DESC" + echo "Select multiple values using checkboxes" + echo " $OPT_VALUES_DESC" + echo " $OPT_TITLE_DESC" ;; "counter") - echo -e "Pick a number in specified range" - echo -e "\t\t$OPT_TITLE_DESC" - echo -e "\t\t$OPT_RANGE_DESC" + echo "Pick a number in specified range" + echo " $OPT_TITLE_DESC" + echo " $OPT_RANGE_DESC" ;; "date") - echo -e "\tPick a date" - echo -e "\t\t$OPT_TITLE_DESC" + echo "Pick a date" + echo " $OPT_TITLE_DESC" ;; "radio") - echo -e "\tPick a single value from radio buttons" - echo -e "\t\t$OPT_VALUES_DESC" - echo -e "\t\t$OPT_TITLE_DESC" + echo "Pick a single value from radio buttons" + echo " $OPT_VALUES_DESC" + echo " $OPT_TITLE_DESC" ;; "sheet") - echo -e "\tPick a value from a sliding bottom sheet interface" - echo -e "\t\t$OPT_VALUES_DESC" - echo -e "\t\t$OPT_TITLE_DESC" + echo "Pick a value from a sliding bottom sheet interface" + echo " $OPT_VALUES_DESC" + echo " $OPT_TITLE_DESC" ;; "spinner") - echo -e "Pick a single value from a dropdown spinner" - echo -e "\t\t$OPT_VALUES_DESC" - echo -e "\t\t$OPT_TITLE_DESC" + echo "Pick a single value from a dropdown spinner" + echo " $OPT_VALUES_DESC" + echo " $OPT_TITLE_DESC" ;; "text") - echo -e "\tInput text (default if no widget specified)" - echo -e "\t\t$OPT_HINT_DESC" - echo -e "\t\t$OPT_PASS_DESC -- cannot use with -m" - echo -e "\t\t$OPT_TITLE_DESC" - echo -e "\t\t$OPT_MULTI_LINE_DESC -- cannot use with -p" + echo "Input text (default if no widget specified)" + echo " $OPT_HINT_DESC" + echo " $OPT_PASS_DESC -- cannot use with -m" + echo " $OPT_TITLE_DESC" + echo " $OPT_MULTI_LINE_DESC -- cannot use with -p" ;; "time") - echo -e "\tPick a time value" - echo -e "\t\t[-p title] dialog title (optional)" + echo "Pick a time value" + echo " [-p title] dialog title (optional)" ;; *) - echo -e "\tUnknown usage for '$1'" + echo "\tUnknown usage for '$1'" ;; esac } From 08c9978afdfbdba7498ca3ca3b319ff397ef9b34 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 14:02:17 -0600 Subject: [PATCH 05/10] Make option usage more clear --- scripts/termux-dialog | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 7249871..3bd36ed 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -17,11 +17,11 @@ declare -a widgets=("confirm" "checkbox" "counter" "date" "radio" "sheet" "spinn # Descriptions for various options that multiple widgets can use OPT_HINT_DESC="[-i hint] text hint (optional)" -OPT_MULTI_LINE_DESC="[-m multi-line] use a textarea with multiple lines instead of single (optional)" -OPT_PASS_DESC="[-p password] enter input as password (optional)" -OPT_TITLE_DESC="[-t title] dialog title (optional)" -OPT_RANGE_DESC="[-r range] min,max,start where each value is a number (optional)" -OPT_VALUES_DESC="[-v values] comma delimited string of values to use (required)" +OPT_MULTI_LINE_DESC="[-m] multiple lines instead of single (optional)" +OPT_PASS_DESC="[-p] enter input as password (optional)" +OPT_TITLE_DESC="[-t title] set title of dialog (optional)" +OPT_RANGE_DESC="[-r min,max,start] comma delim of (3) numbers to use (optional)" +OPT_VALUES_DESC="[-v \",,,\"] comma delim values to use (required)" # Widget hints ARG_I="" @@ -89,7 +89,7 @@ widget_usage () { echo " $OPT_TITLE_DESC" ;; "sheet") - echo "Pick a value from a sliding bottom sheet interface" + echo "Pick a value from sliding bottom sheet" echo " $OPT_VALUES_DESC" echo " $OPT_TITLE_DESC" ;; @@ -101,9 +101,10 @@ widget_usage () { "text") echo "Input text (default if no widget specified)" echo " $OPT_HINT_DESC" - echo " $OPT_PASS_DESC -- cannot use with -m" echo " $OPT_TITLE_DESC" - echo " $OPT_MULTI_LINE_DESC -- cannot use with -p" + echo " $OPT_PASS_DESC*" + echo " $OPT_MULTI_LINE_DESC*" + echo " * cannot use [-m] with [-p]" ;; "time") echo "Pick a time value" From d65a6b9eda95054f6129fe1f2d3dbc3d422f1f28 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 14:16:30 -0600 Subject: [PATCH 06/10] Fix incorrect option description for time widget --- scripts/termux-dialog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 3bd36ed..35206bf 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -108,7 +108,7 @@ widget_usage () { ;; "time") echo "Pick a time value" - echo " [-p title] dialog title (optional)" + echo " $OPT_TITLE_DESC" ;; *) echo "\tUnknown usage for '$1'" From dc71e4d61c41aeeab5b8e665b6221a25f8b03617 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 14:19:18 -0600 Subject: [PATCH 07/10] Shorten main usage --- scripts/termux-dialog | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 35206bf..db129c1 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -6,10 +6,10 @@ DEFAULT_WIDGET="text" SCRIPTNAME=termux-dialog show_usage() { echo "Usage: $SCRIPTNAME widget [options]" - echo "Get user input w/ different widgets! Default Widget: $DEFAULT_WIDGET" - echo " -h, help Show this help" - echo " -l, list Full list all available widgets and their options" - echo " -t, title Set title of input dialog" + echo "Get user input w/ different widgets! Default: $DEFAULT_WIDGET" + echo " -h, help Show this help" + echo " -l, list List all widgets and their options" + echo " -t, title Set title of input dialog (optional)" exit 0 } From bd0f53fee9c3d0a6920672587985c790914a66a7 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 18:35:07 -0600 Subject: [PATCH 08/10] Add [-n] option for numeric text input / other minor tweaks * Change password to send boolean instead * Extract boolean values from boolean params into separate variables to ensure they are sent properly to API * Update help to reflect new API change to allow [-p] and [-m] to work together --- scripts/termux-dialog | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index db129c1..1706b62 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -19,6 +19,7 @@ declare -a widgets=("confirm" "checkbox" "counter" "date" "radio" "sheet" "spinn OPT_HINT_DESC="[-i hint] text hint (optional)" OPT_MULTI_LINE_DESC="[-m] multiple lines instead of single (optional)" OPT_PASS_DESC="[-p] enter input as password (optional)" +OPT_NUMERIC_DESC="[-n] enter input as numbers (optional)" OPT_TITLE_DESC="[-t title] set title of dialog (optional)" OPT_RANGE_DESC="[-r min,max,start] comma delim of (3) numbers to use (optional)" OPT_VALUES_DESC="[-v \",,,\"] comma delim values to use (required)" @@ -29,6 +30,11 @@ OPT_I="" # Text widget multiline ARG_M="" +OPT_M="" + +# Text widget numeric +ARG_N="" +OPT_N="" # Counter range ARG_R="" @@ -36,6 +42,7 @@ OPT_R="" # Text widget input as password ARG_P="" +OPT_P="" # Dialog title (supported by all widgets) ARG_T="" @@ -55,6 +62,7 @@ MULTI_LINE_FLAG=2 PASS_FLAG=4 RANGE_FLAG=8 VALUES_FLAG=16 +NUM_FLAG=32 FLAGS=0 @@ -102,9 +110,10 @@ widget_usage () { echo "Input text (default if no widget specified)" echo " $OPT_HINT_DESC" echo " $OPT_TITLE_DESC" - echo " $OPT_PASS_DESC*" echo " $OPT_MULTI_LINE_DESC*" - echo " * cannot use [-m] with [-p]" + echo " $OPT_NUMERIC_DESC*" + echo " $OPT_PASS_DESC" + echo " * cannot use [-m] with [-n]" ;; "time") echo "Pick a time value" @@ -142,14 +151,15 @@ set_flag () { # Convenience method to get all supported options, regardless of specified widget # NOTE: Option combination validation doesn't occur here parse_options() { - while getopts :hlmpr:i:t:v: option + while getopts :hlmnpr:i:t:v: option do case "$option" in h) show_usage ;; l) list_widgets; exit 0;; i) ARG_I="--es input_hint"; OPT_I="$OPTARG"; set_flag $HINT_FLAG; ;; - m) ARG_M="--ez multiple_lines true"; set_flag $MULTI_LINE_FLAG; ;; - p) ARG_P="--es input_type password"; set_flag $PASS_FLAG; ;; + m) ARG_M="--ez multiple_lines"; OPT_M="true"; set_flag $MULTI_LINE_FLAG; ;; + p) ARG_P="--ez password"; OPT_P="true"; set_flag $PASS_FLAG; ;; + n) ARG_N="--ez numeric"; OPT_N="true"; set_flag $NUM_FLAG; ;; t) ARG_T="--es input_title"; OPT_T="$OPTARG" ;; v) ARG_V="--es input_values"; OPT_V="$OPTARG"; set_flag $VALUES_FLAG; ;; r) ARG_R="--eia input_range"; OPT_R=$OPTARG; set_flag $RANGE_FLAG; ;; @@ -192,19 +202,19 @@ case "$WIDGET" in options_error $WIDGET fi - if [ $((FLAGS & MULTI_LINE_FLAG)) -ne 0 ] && [ $((FLAGS & PASS_FLAG)) -ne 0 ]; then + if [ $((FLAGS & MULTI_LINE_FLAG)) -ne 0 ] && [ $((FLAGS & NUM_FLAG)) -ne 0 ]; then options_error $WIDGET fi ;; "confirm") - if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG))) -ne 0 ]; then + if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then options_error $WIDGET fi ;; "counter") - if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | VALUES_FLAG))) -ne 0 ]; then + if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then options_error $WIDGET fi ;; @@ -214,7 +224,7 @@ case "$WIDGET" in echo "ERROR: '$WIDGET' takes no arguments"; exit 1; fi - if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG))) -ne 0 ]; then + if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then options_error $WIDGET fi ;; @@ -225,7 +235,7 @@ case "$WIDGET" in exit 1 fi - if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG))) -ne 0 ]; then + if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | NUM_FLAG))) -ne 0 ]; then options_error $WIDGET fi ;; @@ -248,8 +258,8 @@ if [ -n "$ARG_I" ]; then set -- "$@" $ARG_I "$OPT_I"; fi if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi if [ -n "$ARG_R" ]; then set -- "$@" $ARG_R "$OPT_R"; fi if [ -n "$ARG_V" ]; then set -- "$@" $ARG_V "$OPT_V"; fi -if [ -n "$ARG_M" ]; then set -- "$@" $ARG_M ""; fi -if [ -n "$ARG_P" ]; then set -- "$@" $ARG_P ""; fi - +if [ -n "$ARG_M" ]; then set -- "$@" $ARG_M "$OPT_M"; fi +if [ -n "$ARG_P" ]; then set -- "$@" $ARG_P "$OPT_P"; fi +if [ -n "$ARG_N" ]; then set -- "$@" $ARG_N "$OPT_N"; fi /data/data/com.termux/files/usr/libexec/termux-api Dialog "$@" From 0c8a321abc9e9dcc04ee2753d3452f236363797a Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 18:54:25 -0600 Subject: [PATCH 09/10] Make option help ordering more consistent --- scripts/termux-dialog | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 1706b62..1a86dc8 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -74,8 +74,8 @@ widget_usage () { case "$1" in "confirm") echo "Show confirmation dialog" - echo " $OPT_TITLE_DESC" echo " $OPT_HINT_DESC" + echo " $OPT_TITLE_DESC" ;; "checkbox") echo "Select multiple values using checkboxes" @@ -84,8 +84,8 @@ widget_usage () { ;; "counter") echo "Pick a number in specified range" - echo " $OPT_TITLE_DESC" echo " $OPT_RANGE_DESC" + echo " $OPT_TITLE_DESC" ;; "date") echo "Pick a date" @@ -109,10 +109,10 @@ widget_usage () { "text") echo "Input text (default if no widget specified)" echo " $OPT_HINT_DESC" - echo " $OPT_TITLE_DESC" echo " $OPT_MULTI_LINE_DESC*" echo " $OPT_NUMERIC_DESC*" echo " $OPT_PASS_DESC" + echo " $OPT_TITLE_DESC" echo " * cannot use [-m] with [-n]" ;; "time") From a0622d0b8316b17f475c4d5fd5a1b0e2d8aa5fe7 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Wed, 20 Jun 2018 19:00:38 -0600 Subject: [PATCH 10/10] Add neglected speech widget / speech validation --- scripts/termux-dialog | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/termux-dialog b/scripts/termux-dialog index 1a86dc8..5c6c2eb 100755 --- a/scripts/termux-dialog +++ b/scripts/termux-dialog @@ -13,7 +13,7 @@ show_usage() { exit 0 } -declare -a widgets=("confirm" "checkbox" "counter" "date" "radio" "sheet" "spinner" "text" "time") +declare -a widgets=("confirm" "checkbox" "counter" "date" "radio" "sheet" "spinner" "speech" "text" "time") # Descriptions for various options that multiple widgets can use OPT_HINT_DESC="[-i hint] text hint (optional)" @@ -101,6 +101,11 @@ widget_usage () { echo " $OPT_VALUES_DESC" echo " $OPT_TITLE_DESC" ;; + "speech") + echo "Obtain speech using device microphone" + echo " $OPT_HINT_DESC" + echo " $OPT_TITLE_DESC" + ;; "spinner") echo "Pick a single value from a dropdown spinner" echo " $OPT_VALUES_DESC" @@ -219,11 +224,13 @@ case "$WIDGET" in fi ;; - "date" | "speech" | "time") - if [ $# -gt 0 ]; then - echo "ERROR: '$WIDGET' takes no arguments"; exit 1; + "speech") + if [ $((FLAGS & (MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then + options_error $WIDGET fi + ;; + "date" | "time") if [ $((FLAGS & (HINT_FLAG | MULTI_LINE_FLAG | PASS_FLAG | RANGE_FLAG | VALUES_FLAG | NUM_FLAG))) -ne 0 ]; then options_error $WIDGET fi