Advertisement
vonschutter

animationwontnotprintstdoutwhenterm

Apr 27th, 2023
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.97 KB | None | 0 0
  1.     ecode="\033["
  2.  
  3.     yellow="${ecode}1;33m"
  4.     darkyellow="${ecode}0;33m"
  5.     red="${ecode}1;31m"
  6.     darkred="${ecode}0;31m"
  7.     endcolor="${ecode}0m"
  8.     green="${ecode}1;32m"
  9.     darkgreen="${ecode}1;32m"
  10.     blue="${ecode}1;34m"
  11.     darkblue="${ecode}0;34m"
  12.     cyan="${ecode}0;36"
  13.     darkcyan="${ecode}0;36"
  14.     gray="${ecode}0;37"
  15.     purple="${ecode}1;35"
  16.     darkpurple="${ecode}0;35"
  17.  
  18.     # Back compatability w. old scripts
  19.     export YELLOW="$yellow"
  20.     export RED="$red"
  21.     export ENDCOLOR="$endcolor"
  22.     export GREEN="$green"
  23.     export BLUE="$blue"
  24.  
  25.     anim=(
  26.     "${blue}${green}${red}${magenta}•    "
  27.     " ${green}${red}${magenta}${blue}•   "
  28.     "  ${red}${magenta}${blue}${green}•  "
  29.     "   ${magenta}${blue}${green}${red}• "
  30.     "    ${blue}${green}${red}${magenta}•"
  31.     )
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. anim::start_animation () {
  39. # Description:
  40. # A simple function to display and animation during a silent acton
  41. #
  42. # Globals:
  43. # Arguments:
  44. # Outputs: Standard out
  45. # Returns:
  46. # Usage:
  47. # oem::start_animation ; EXPRESSION of COMMAND or FUNCTION
  48. # oem::stop_animation
  49. #
  50. # End of documentation
  51.  
  52.     setterm -cursor off
  53.     export ANIM_PID="0"
  54.     (
  55.     while true; do
  56.         for i in {0..4}; do
  57.             printf "\r\033[2K                                                 ${anim[i]}"
  58.             sleep 0.1
  59.         done
  60.  
  61.         for i in {4..0}; do
  62.             printf "\r\033[2K                                                 ${anim[i]}"
  63.             sleep 0.1
  64.         done
  65.     done
  66.     ) &
  67.    
  68.     export ANIM_PID="${!}"
  69. }
  70.  
  71.  
  72.  
  73. test_me () {
  74.   write_warning "WARNING: blablablabla"
  75.   anim::start_animation; sleep 5; anim::stop_animation
  76. }
  77.  
  78.  
  79. anim::stop_animation () {
  80. # Description:
  81. # A simple function to STOP display and animation during a silent acton
  82. #
  83. # Globals:
  84. # Arguments:
  85. # Outputs: Standard out
  86. # Returns:
  87. # Usage:
  88. # oem::start_animation ; EXPRESSION of COMMAND or FUNCTION
  89. # oem::stop_animation
  90. #
  91. # End of documentation
  92.  
  93.     [[ -e "/proc/${ANIM_PID}" ]]  && kill SIGPIPE "${ANIM_PID}"  &>/dev/null
  94.     setterm -cursor on
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement