Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Last active July 12, 2020 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beccasaurus/37c2c07830e8c607d7323939d70d2d16 to your computer and use it in GitHub Desktop.
Save beccasaurus/37c2c07830e8c607d7323939d70d2d16 to your computer and use it in GitHub Desktop.
#! /bin/bash
trap 'echo "Exiting..."; exit 1' SIGINT
up='[A'
down='[B'
right='[C'
left='[D'
special=""
character=""
input=""
redraw() {
clear
echo "Input: $input"
}
handle_special_character() {
echo "Special Character: $special"
}
redraw
while true
do
if read -t 1 -n 1 -s -r
then
character="$( echo -e "$REPLY" | cat -v )"
if [ "$character" = "^[" ]
then
special="$character"
continue
elif [ -n "$special" ]
then
special="${special}$character"
if [ "$character" = "[" ]
then
continue
else
handle_special_character
special=""
continue
fi
fi
if [ "$character" = "^?" ]
then
if [ ${#input} -gt 0 ]
then
input="${input:0:$((${#input}-1))}"
fi
elif [ ${#character} -eq 1 ]
then
input="${input}$character"
elif [ ${#character} -eq 0 ]
then
echo "Submitted!"
break
fi
redraw
else
:
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment