Advertisement
metalx1000

Colors and Shapes Video Player

Mar 4th, 2019
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.60 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #https://www.youtube.com/watch?v=lnkgofmsVDU
  4. #https://www.youtube.com/watch?v=uzcWMhjcZUk
  5. #https://www.youtube.com/watch?v=ZeXKh17JzaI
  6. #https://www.youtube.com/watch?v=y2O5DaCWWOo
  7. #https://www.youtube.com/watch?v=QHf6XbgtEuM
  8. #https://www.youtube.com/watch?v=oySpzYnveCc
  9. #https://www.youtube.com/watch?v=haBX7ezGb04
  10. #https://www.youtube.com/watch?v=MGkC7re50QM
  11.  
  12. list="$(grep '^#http' $0|cut -d\# -f2)"
  13. readarray -t list <<< "$list"
  14.  
  15. function select_option {
  16.  
  17.     # little helpers for terminal print control and key input
  18.     ESC=$( printf "\033")
  19.     cursor_blink_on()  { printf "$ESC[?25h"; }
  20.     cursor_blink_off() { printf "$ESC[?25l"; }
  21.     cursor_to()        { printf "$ESC[$1;${2:-1}H"; }
  22.     print_option()     { printf "   $1 "; }
  23.     print_selected()   { printf "  $ESC[7m $1 $ESC[27m"; }
  24.     get_cursor_row()   { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; }
  25.     key_input()        { read -s -n3 key 2>/dev/null >&2
  26.                          if [[ $key = $ESC[A ]]; then echo up;    fi
  27.                          if [[ $key = $ESC[B ]]; then echo down;  fi
  28.                          if [[ $key = ""     ]]; then echo enter; fi; }
  29.  
  30.     # initially print empty new lines (scroll down if at bottom of screen)
  31.     for opt; do printf "\n"; done
  32.  
  33.     # determine current screen position for overwriting the options
  34.     local lastrow=`get_cursor_row`
  35.     local startrow=$(($lastrow - $#))
  36.  
  37.     # ensure cursor and input echoing back on upon a ctrl+c during read -s
  38.     trap "cursor_blink_on; stty echo; printf '\n'; exit" 2
  39.     cursor_blink_off
  40.  
  41.     local selected=0
  42.     while true; do
  43.         # print options by overwriting the last lines
  44.         local idx=0
  45.         for opt; do
  46.             cursor_to $(($startrow + $idx))
  47.             if [ $idx -eq $selected ]; then
  48.                 print_selected "$opt"
  49.             else
  50.                 print_option "$opt"
  51.             fi
  52.             ((idx++))
  53.         done
  54.  
  55.         # user key control
  56.         case `key_input` in
  57.             enter) break;;
  58.             up)    ((selected--));
  59.                    if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;;
  60.             down)  ((selected++));
  61.                    if [ $selected -ge $# ]; then selected=0; fi;;
  62.         esac
  63.     done
  64.  
  65.     # cursor position back to normal
  66.     cursor_to $lastrow
  67.     printf "\n"
  68.     cursor_blink_on
  69.  
  70.     return $selected
  71. }
  72.  
  73. echo "Select one option using up/down keys and enter to confirm:"
  74. echo
  75.  
  76. select_option "${list[@]}"
  77. choice=$?
  78.  
  79. echo "Choosen index = $choice"
  80. echo "        value = ${list[$choice]}"
  81. mpv --fs "${list[$choice]}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement