Merge pull request #28 from dkramer95/coloredToast

Add text color, bg color, and gravity options to termux-toast
This commit is contained in:
Fredrik Fornwall 2018-06-24 01:31:36 +02:00 committed by GitHub
commit 3e2a967bea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,26 +1,35 @@
#!/data/data/com.termux/files/usr/bin/sh #!/data/data/com.termux/files/usr/bin/bash
set -e -u set -e -u
SCRIPTNAME=termux-toast SCRIPTNAME=termux-toast
show_usage () { show_usage () {
echo "Usage: termux-toast [-s] [text]" echo "Usage: termux-toast [-b bgcolor] [-c color] [-g gravity] [-s] [text]"
echo "Show text in a Toast (a transient popup). The text to show is either supplied as arguments or read from stdin if no arguments are given." echo "Show text in a Toast (a transient popup). The text to show is either supplied as arguments or read from stdin if no arguments are given."
echo " -h show this help"
echo " -b set background color (default: gray)"
echo " -c set text color (default: white)"
echo " -g set position of toast: [top, middle, or bottom] (default: middle)"
echo " -s only show the toast for a short while" echo " -s only show the toast for a short while"
echo "NOTE: color can be a standard name (i.e. red) or 6 / 8 digit hex value (i.e. \"#FF0000\" or \"#FFFF0000\") where order is (AA)RRGGBB. Invalid color will revert to default value"
exit 0 exit 0
} }
PARAMS="" PARAMS=""
while getopts :hs option while getopts :hsc:b:g: option
do do
case "$option" in case "$option" in
h) show_usage;; h) show_usage;;
s) PARAMS="--ez short true";; s) PARAMS=" --ez short true";;
c) PARAMS+=" --es text_color $OPTARG";;
b) PARAMS+=" --es background $OPTARG";;
g) PARAMS+=" --es gravity $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac esac
done done
shift $(($OPTIND-1)) shift $(($OPTIND-1))
CMD="/data/data/com.termux/files/usr/libexec/termux-api Toast $PARAMS" CMD="/data/data/com.termux/files/usr/libexec/termux-api Toast $PARAMS"
if [ $# = 0 ]; then if [ $# = 0 ]; then
$CMD $CMD
else else