summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. 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)
commitcd3a9928c24d504cb67338921a3a3c1ac3178c22 (patch)
treecf511267830a816eb40ea58736f1242aa8aec14a /src
parentacd042453efecb299559b54b4cf5a0564a65fde8 (diff)
downloadfirman.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')
-rw-r--r--src/ui/tui.sh15
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