diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/tui.sh | 66 |
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 |