summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2015-10-27 14:39:22 (EDT)
committer P. J. McDermott <pj@pehjota.net>2015-10-27 14:39:22 (EDT)
commita08e15af13b9cc43cbbacc3e25bbaa75d1e52093 (patch)
tree2c61123736738da126bb2329abe6eda73ab49a85 /src
parentd1bb2690d4892c63db6de266dfdde9dc434a187d (diff)
downloadfirman.sh-a08e15af13b9cc43cbbacc3e25bbaa75d1e52093.zip
firman.sh-a08e15af13b9cc43cbbacc3e25bbaa75d1e52093.tar.gz
firman.sh-a08e15af13b9cc43cbbacc3e25bbaa75d1e52093.tar.bz2
cli_show_menu(): New function
Diffstat (limited to 'src')
-rw-r--r--src/ui/cli.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/ui/cli.sh b/src/ui/cli.sh
index a396625..a8af8dd 100644
--- a/src/ui/cli.sh
+++ b/src/ui/cli.sh
@@ -46,3 +46,40 @@ cli_err()
printf "Error: ${fmt}\n" "${@}" >&2
}
+
+cli_show_menu()
+{
+ local title="${1}"
+ shift 1
+ local i=
+ local l=
+ local label=
+
+ printf '%s\n' "${title}" >"$(tty)"
+ { printf '%s\n' "${title}" | sed 's/./-/g'; } >"$(tty)"
+
+ while :; do
+ printf '\n' >"$(tty)"
+ i=0
+ l=${#}
+ for label in "${@}"; do
+ i=$(($i + 1))
+ printf ' %4d: %s\n' "${i}" "${label}" >"$(tty)"
+ done
+ printf '\n> ' >"$(tty)"
+ if ! read -r i <"$(tty)"; then
+ continue
+ fi
+ case "${i}" in
+ *[!0-9]* | '')
+ continue
+ ;;
+ esac
+ if [ ${i} -le 0 ] || [ ${i} -gt ${l} ]; then
+ continue
+ fi
+ i=$(($i - 1))
+ printf '%d' "${i}"
+ return 0
+ done
+}