diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-10-29 01:02:38 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2015-10-29 01:02:38 (EDT) |
commit | cd3a9928c24d504cb67338921a3a3c1ac3178c22 (patch) | |
tree | cf511267830a816eb40ea58736f1242aa8aec14a /src/ui | |
parent | acd042453efecb299559b54b4cf5a0564a65fde8 (diff) | |
download | firman.sh-cd3a9928c24d504cb67338921a3a3c1ac3178c22.zip firman.sh-cd3a9928c24d504cb67338921a3a3c1ac3178c22.tar.gz firman.sh-cd3a9928c24d504cb67338921a3a3c1ac3178c22.tar.bz2 |
tui_show_prompt(): Implement KEY_BACKSPACE line editing
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/tui.sh | 15 |
1 files changed, 11 insertions, 4 deletions
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 |