I want to incrementally read a line of input from the terminal, and allow the user some basic line editing functionality; INS, DEL, RIGHT, LEFT HOME, END, BACKSPACE
Each time the string is modified, I want to process it, to do an incremental regex search of a text file.
These edit-keys, and others, generate multiple input characters which
make it rather difficult to interpret the input, eg C-Left generates 6 characters.
Is there a simple way to achieve this char-by-char editable input?
I'm especialy interested in knowing how to do this in bash, because the rest of the processing will be bash..
Other suggestions are welcome too..
Here is how I started out, but it gets a bit out of hand with such a potential variety of control codes ..
#!/bin/bash
IFS=$'\n'
while true ;do
read -n 1 c
((${#c}==0)) && break # Exit the loop. Input length is 0
# ie. The user has pressed Enter
echo "xx=$(echo -n "$c"|xxd -p)="
# 1b 5b 32 7e "INS"
# 1b 5b 33 7e "DEL"
# 1b 5b 43 "RIGHT"
# 1b 5b 44 "LEFT"
# 1b 5b 46 "END"
# 1b 5b 48 "HOME"
# 7f "BACKSPACE"
done