Last active
July 12, 2020 07:05
-
-
Save beccasaurus/37c2c07830e8c607d7323939d70d2d16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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