From cd3a9928c24d504cb67338921a3a3c1ac3178c22 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 29 Oct 2015 01:02:38 -0400 Subject: tui_show_prompt(): Implement KEY_BACKSPACE line editing --- (limited to 'src/ui') diff --git a/src/ui/tui.sh b/src/ui/tui.sh index 6cf0f9f..34c3a61 100644 --- a/src/ui/tui.sh +++ b/src/ui/tui.sh @@ -262,10 +262,17 @@ tui_show_prompt() fi ;; KEY_BACKSPACE) - if [ ${curpos} -gt 0 ]; then - input="${input%?}" - curpos=$(($curpos - 1)) - fi + [ ${curpos} -gt 0 ] || continue + i=1 + mask='' + while [ ${i} -lt ${curpos} ]; do + mask="${mask}." + i=$(($i + 1)) + done + cmd="s/^\\(${mask}\\).\\(.*\\)\$/\1\2/" + input="$(printf '%s' "${input}" | sed \ + "${cmd}")" + curpos=$(($curpos - 1)) ;; KEY_DEL) [ ${curpos} -lt ${#input} ] || continue -- cgit v0.9.1