summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2015-10-29 00:59:43 (EDT)
committer P. J. McDermott <pj@pehjota.net>2015-10-29 00:59:43 (EDT)
commitacd042453efecb299559b54b4cf5a0564a65fde8 (patch)
treeb40b65cd6c8d444353aaaa95a6e7d075d593dafb /src
parent9dcc5b86e73fda790dd81fdbb12ae33534144515 (diff)
downloadfirman.sh-acd042453efecb299559b54b4cf5a0564a65fde8.zip
firman.sh-acd042453efecb299559b54b4cf5a0564a65fde8.tar.gz
firman.sh-acd042453efecb299559b54b4cf5a0564a65fde8.tar.bz2
tui_show_prompt(): Implement line editing
Diffstat (limited to 'src')
-rw-r--r--src/ui/tui.sh66
1 files changed, 53 insertions, 13 deletions
diff --git a/src/ui/tui.sh b/src/ui/tui.sh
index b121906..6cf0f9f 100644
--- a/src/ui/tui.sh
+++ b/src/ui/tui.sh
@@ -188,6 +188,8 @@ tui_show_prompt()
local curpos=0
local focus=0
local key=
+ local mask=
+ local buffer=
# Calculate width and draw the box.
w=$(expr ${#title} + 4)
@@ -266,24 +268,62 @@ tui_show_prompt()
fi
;;
KEY_DEL)
- if [ ${curpos} -lt ${#input} ]; then
- : TODO
- fi
+ [ ${curpos} -lt ${#input} ] || continue
+ i=0
+ mask=''
+ while [ ${i} -lt ${curpos} ]; do
+ mask="${mask}."
+ i=$(($i + 1))
+ done
+ cmd="s/^\\(${mask}\\).\\(.*\\)\$/\1\2/"
+ input="$(printf '%s' "${input}" | sed \
+ "${cmd}")"
;;
KEY_SPACE)
- if [ ${curpos} -lt ${len} ]; then
- # TODO: Handle curpos not at end
- input="${input} "
- curpos=$(($curpos + 1))
- fi
+ [ ${curpos} -lt ${len} ] || continue
+ key=' '
+ i=0
+ mask=''
+ while [ ${i} -lt ${curpos} ]; do
+ mask="${mask}."
+ i=$(($i + 1))
+ done
+ cmd="s/^\\(${mask}\\).*\$/\1/"
+ buffer="$(printf '%s' "${input}" | sed \
+ "${cmd}")${key}"
+ i=${curpos}
+ mask=''
+ while [ ${i} -lt ${#input} ]; do
+ mask="${mask}."
+ i=$(($i + 1))
+ done
+ cmd="s/^.*\\(${mask}\\)\$/\1/"
+ input="${buffer}$(printf '%s' \
+ "${input}" | sed "${cmd}")"
+ curpos=$(($curpos + 1))
;;
KEY_*);;
*)
- if [ ${curpos} -lt ${len} ]; then
- # TODO: Handle curpos not at end
- input="${input}${key}"
- curpos=$(($curpos + 1))
- fi
+ [ ${curpos} -lt ${len} ] || continue
+ i=0
+ mask=''
+ while [ ${i} -lt ${curpos} ]; do
+ mask="${mask}."
+ i=$(($i + 1))
+ done
+ cmd="s/^\\(${mask}\\).*\$/\1/"
+ buffer="$(printf '%s' "${input}" | sed \
+ "${cmd}")${key}"
+ i=${curpos}
+ mask=''
+ while [ ${i} -lt ${#input} ]; do
+ mask="${mask}."
+ i=$(($i + 1))
+ done
+ cmd="s/^.*\\(${mask}\\)\$/\1/"
+ input="${buffer}$(printf '%s' \
+ "${input}" | sed "${cmd}")"
+ curpos=$(($curpos + 1))
;;
esac
elif [ ${focus} -eq 1 ]; then