diff options
author | P. 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) |
commit | a08e15af13b9cc43cbbacc3e25bbaa75d1e52093 (patch) | |
tree | 2c61123736738da126bb2329abe6eda73ab49a85 | |
parent | d1bb2690d4892c63db6de266dfdde9dc434a187d (diff) | |
download | firman.sh-a08e15af13b9cc43cbbacc3e25bbaa75d1e52093.zip firman.sh-a08e15af13b9cc43cbbacc3e25bbaa75d1e52093.tar.gz firman.sh-a08e15af13b9cc43cbbacc3e25bbaa75d1e52093.tar.bz2 |
cli_show_menu(): New function
-rw-r--r-- | src/ui/cli.sh | 37 |
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 +} |