Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # betlog - 2019-04-27
- # modified from : https://stackoverflow.com/questions/10679188/casing-arrow-keys-in-bash
- #
- MIN=00
- MAX=99
- #-------
- count=00
- echo $(printf %02d $count)
- escape_char=$(printf "\u1b")
- while :; do
- read -rsn1 mode # get 1 character
- if [[ $mode == $escape_char ]]; then
- read -rsn2 mode # read 2 more chars
- fi
- case $mode in
- 'q') echo QUITTING ; exit ;;
- '[A') echo UP ;;
- '[B') echo DN ;;
- '[D') #leftarrow
- echo -ne "RESET \a\n"
- let count=00
- echo $(printf %02d $count)
- ;;
- '[C') #rightarrow
- if [[ $count -gt $MAX-1 ]]; then
- echo -ne "NOPE \a\n"
- else
- let count=count+1
- echo $(printf %02d $count)
- fi
- ;;
- *) >&2 echo 'ERR bad input'; return ;;
- esac
- done
Add Comment
Please, Sign In to add comment