betlog

https://www.facebook.com/groups/RasPiCommunity/permalink/117

Apr 27th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # betlog - 2019-04-27
  3. # modified from : https://stackoverflow.com/questions/10679188/casing-arrow-keys-in-bash
  4. #
  5. MIN=00
  6. MAX=99
  7. #-------
  8. count=00
  9. echo $(printf %02d $count)
  10. escape_char=$(printf "\u1b")
  11. while :; do
  12.     read -rsn1 mode # get 1 character
  13.     if [[ $mode == $escape_char ]]; then
  14.         read -rsn2 mode # read 2 more chars
  15.     fi
  16.     case $mode in
  17.         'q') echo QUITTING ; exit ;;
  18.         '[A') echo UP ;;
  19.         '[B') echo DN ;;
  20.         '[D')  #leftarrow
  21.             echo -ne "RESET \a\n"
  22.             let count=00
  23.             echo $(printf %02d $count)
  24.             ;;
  25.         '[C') #rightarrow
  26.             if [[ $count -gt $MAX-1 ]]; then
  27.                 echo -ne "NOPE \a\n"
  28.             else
  29.                 let count=count+1
  30.                 echo $(printf %02d $count)
  31.             fi
  32.             ;;
  33.         *) >&2 echo 'ERR bad input'; return ;;
  34.     esac
  35. done
Add Comment
Please, Sign In to add comment