betlog

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

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