summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2015-10-30 16:54:49 (EDT)
committer P. J. McDermott <pj@pehjota.net>2015-10-30 16:54:49 (EDT)
commit766225df49bac22581d121e7962c5613d2a0006c (patch)
treed4c1a1723f44c3172246d0ce46fdd96497ce0883 /src
parent91e181d64c047ac3e8b2f7efc344ae2b73bb2d43 (diff)
downloadfirman.sh-766225df49bac22581d121e7962c5613d2a0006c.zip
firman.sh-766225df49bac22581d121e7962c5613d2a0006c.tar.gz
firman.sh-766225df49bac22581d121e7962c5613d2a0006c.tar.bz2
tui_show_menu(): Add a Cancel button
Diffstat (limited to 'src')
-rw-r--r--src/ui/tui.sh21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/ui/tui.sh b/src/ui/tui.sh
index 85f2fe1..0aca904 100644
--- a/src/ui/tui.sh
+++ b/src/ui/tui.sh
@@ -203,6 +203,9 @@ tui_show_menu()
w=$(expr ${#label} + 6)
fi
done
+ if [ ${w} -lt 17 ]; then
+ w=17
+ fi
lsth=${#}
h=$(($lsth + 8))
if [ ${h} -gt $(term_lines) ]; then
@@ -229,8 +232,8 @@ tui_show_menu()
# Event loop.
while :; do
- # Draw a button.
- term_cursor_position $(($y + $h - 2)) $(($x + $w - 6))
+ # Draw buttons.
+ term_cursor_position $(($y + $h - 2)) $(($x + $w - 15))
if [ ${focus} -eq 1 ]; then
term_attr_on reverse
term_write '[OK]'
@@ -238,6 +241,14 @@ tui_show_menu()
else
term_write '[OK]'
fi
+ term_write ' '
+ if [ ${focus} -eq 2 ]; then
+ term_attr_on reverse
+ term_write '[Cancel]'
+ term_attr_off reverse
+ else
+ term_write '[Cancel]'
+ fi
# Draw a box.
term_cursor_position $(($y + 3)) $(($x + 2))
@@ -292,7 +303,7 @@ tui_show_menu()
# Input.
key="$(term_getch)"
if [ "x${key}" = xKEY_TAB ]; then
- focus=$(expr \( ${focus} + 1 \) % 2)
+ focus=$(expr \( ${focus} + 1 \) % 3)
elif [ ${focus} -eq 0 ]; then
case "${key}" in
KEY_ENTER) break;;
@@ -326,6 +337,10 @@ tui_show_menu()
case "${key}" in
KEY_ENTER | KEY_SPACE) break;;
esac
+ elif [ ${focus} -eq 2 ]; then
+ case "${key}" in
+ KEY_ENTER | KEY_SPACE) return 1;;
+ esac
fi
done