summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-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
+}