diff options
-rw-r--r-- | src/ui/cli.sh | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/ui/cli.sh b/src/ui/cli.sh index 9262cc1..8bc18a1 100644 --- a/src/ui/cli.sh +++ b/src/ui/cli.sh @@ -15,9 +15,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +cli_tty='' + cli_init_ui() { - : Nothing to do. + cli_tty="$(tty)" } cli_exit_ui() @@ -35,7 +37,7 @@ cli_dbg() local fmt="${1}" shift 1 - printf "Debug: ${fmt}\n" "${@}" >"$(tty)" + printf "Debug: ${fmt}\n" "${@}" >"${cli_tty}" } cli_info() @@ -43,7 +45,7 @@ cli_info() local fmt="${1}" shift 1 - printf "${fmt}\n" "${@}" >"$(tty)" + printf "${fmt}\n" "${@}" >"${cli_tty}" } cli_warn() @@ -51,7 +53,7 @@ cli_warn() local fmt="${1}" shift 1 - printf "Warning: ${fmt}\n" "${@}" >"$(tty)" + printf "Warning: ${fmt}\n" "${@}" >"${cli_tty}" } cli_err() @@ -59,7 +61,7 @@ cli_err() local fmt="${1}" shift 1 - printf "Error: ${fmt}\n" "${@}" >"$(tty)" + printf "Error: ${fmt}\n" "${@}" >"${cli_tty}" } cli_show_menu() @@ -70,19 +72,19 @@ cli_show_menu() local l= local label= - printf '%s\n' "${title}" >"$(tty)" - { printf '%s\n' "${title}" | sed 's/./-/g'; } >"$(tty)" + printf '%s\n' "${title}" >"${cli_tty}" + { printf '%s\n' "${title}" | sed 's/./-/g'; } >"${cli_tty}" while :; do - printf '\n' >"$(tty)" + printf '\n' >"${cli_tty}" i=0 l=${#} for label in "${@}"; do i=$(($i + 1)) - printf ' %4d: %s\n' "${i}" "${label}" >"$(tty)" + printf ' %4d: %s\n' "${i}" "${label}" >"${cli_tty}" done - printf '\n> ' >"$(tty)" - if ! read -r i <"$(tty)"; then + printf '\n> ' >"${cli_tty}" + if ! read -r i <"${cli_tty}"; then continue fi case "${i}" in |