mirror of
https://github.com/molovo/revolver.git
synced 2026-09-10 06:36:14 -04:00
Add additional spinner styles
Also adds the `--style` option to allow selection
This commit is contained in:
parent
555bdd7f19
commit
964910b97b
98
revolver
98
revolver
|
|
@ -1,5 +1,64 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
local -A _revolver_spinners
|
||||
_revolver_spinners=(
|
||||
'dots' '0.08 ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏'
|
||||
'dots2' '0.08 ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷'
|
||||
'dots3' '0.08 ⠋ ⠙ ⠚ ⠞ ⠖ ⠦ ⠴ ⠲ ⠳ ⠓'
|
||||
'dots4' '0.08 ⠄ ⠆ ⠇ ⠋ ⠙ ⠸ ⠰ ⠠ ⠰ ⠸ ⠙ ⠋ ⠇ ⠆'
|
||||
'dots5' '0.08 ⠋ ⠙ ⠚ ⠒ ⠂ ⠂ ⠒ ⠲ ⠴ ⠦ ⠖ ⠒ ⠐ ⠐ ⠒ ⠓ ⠋'
|
||||
'dots6' '0.08 ⠁ ⠉ ⠙ ⠚ ⠒ ⠂ ⠂ ⠒ ⠲ ⠴ ⠤ ⠄ ⠄ ⠤ ⠴ ⠲ ⠒ ⠂ ⠂ ⠒ ⠚ ⠙ ⠉ ⠁'
|
||||
'dots7' '0.08 ⠈ ⠉ ⠋ ⠓ ⠒ ⠐ ⠐ ⠒ ⠖ ⠦ ⠤ ⠠ ⠠ ⠤ ⠦ ⠖ ⠒ ⠐ ⠐ ⠒ ⠓ ⠋ ⠉ ⠈'
|
||||
'dots8' '0.08 ⠁ ⠁ ⠉ ⠙ ⠚ ⠒ ⠂ ⠂ ⠒ ⠲ ⠴ ⠤ ⠄ ⠄ ⠤ ⠠ ⠠ ⠤ ⠦ ⠖ ⠒ ⠐ ⠐ ⠒ ⠓ ⠋ ⠉ ⠈ ⠈'
|
||||
'dots9' '0.08 ⢹ ⢺ ⢼ ⣸ ⣇ ⡧ ⡗ ⡏'
|
||||
'dots10' '0.08 ⢄ ⢂ ⢁ ⡁ ⡈ ⡐ ⡠'
|
||||
'dots11' '0.1 ⠁ ⠂ ⠄ ⡀ ⢀ ⠠ ⠐ ⠈'
|
||||
'dots12' '0.08 "⢀⠀" "⡀⠀" "⠄⠀" "⢂⠀" "⡂⠀" "⠅⠀" "⢃⠀" "⡃⠀" "⠍⠀" "⢋⠀" "⡋⠀" "⠍⠁" "⢋⠁" "⡋⠁" "⠍⠉" "⠋⠉" "⠋⠉" "⠉⠙" "⠉⠙" "⠉⠩" "⠈⢙" "⠈⡙" "⢈⠩" "⡀⢙" "⠄⡙" "⢂⠩" "⡂⢘" "⠅⡘" "⢃⠨" "⡃⢐" "⠍⡐" "⢋⠠" "⡋⢀" "⠍⡁" "⢋⠁" "⡋⠁" "⠍⠉" "⠋⠉" "⠋⠉" "⠉⠙" "⠉⠙" "⠉⠩" "⠈⢙" "⠈⡙" "⠈⠩" "⠀⢙" "⠀⡙" "⠀⠩" "⠀⢘" "⠀⡘" "⠀⠨" "⠀⢐" "⠀⡐" "⠀⠠" "⠀⢀" "⠀⡀"'
|
||||
'line' '0.13 - \\ | /'
|
||||
'line2' '0.1 ⠂ - – — – -'
|
||||
'pipe' '0.1 ┤ ┘ ┴ └ ├ ┌ ┬ ┐'
|
||||
'simpleDots' '0.4 ". " ".. " "..." " "'
|
||||
'simpleDotsScrolling' '0.2 ". " ".. " "..." " .." " ." " "'
|
||||
'star' '0.07 ✶ ✸ ✹ ✺ ✹ ✷'
|
||||
'star2' '0.08 + x *'
|
||||
'flip' "0.07 _ _ _ - \` \` ' ´ - _ _ _"
|
||||
'hamburger' '0.1 ☱ ☲ ☴'
|
||||
'growVertical' '0.12 ▁ ▃ ▄ ▅ ▆ ▇ ▆ ▅ ▄ ▃'
|
||||
'growHorizontal' '0.12 ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▊ ▋ ▌ ▍ ▎'
|
||||
'balloon' '0.14 " " "." "o" "O" "@" "*" " "'
|
||||
'balloon2' '0.12 . o O ° O o .'
|
||||
'noise' '▓ ▒ ░'
|
||||
'bounce' '0.1 ⠁ ⠂ ⠄ ⠂'
|
||||
'boxBounce' '0.12 ▖ ▘ ▝ ▗'
|
||||
'boxBounce2' '0.1 ▌ ▀ ▐ ▄'
|
||||
'triangle' '0.05 ◢ ◣ ◤ ◥'
|
||||
'arc' '0.1 ◜ ◠ ◝ ◞ ◡ ◟'
|
||||
'circle' '0.12 ◡ ⊙ ◠'
|
||||
'squareCorners' '0.18 ◰ ◳ ◲ ◱'
|
||||
'circleQuarters' '0.12 ◴ ◷ ◶ ◵'
|
||||
'circleHalves' '0.05 ◐ ◓ ◑ ◒'
|
||||
'squish' '0.1 ╫ ╪'
|
||||
'toggle' '0.25 ⊶ ⊷'
|
||||
'toggle2' '0.08 ▫ ▪'
|
||||
'toggle3' '0.12 □ ■'
|
||||
'toggle4' '0.1 ■ □ ▪ ▫'
|
||||
'toggle5' '0.1 ▮ ▯'
|
||||
'toggle6' '0.3 ဝ ၀'
|
||||
'toggle7' '0.08 ⦾ ⦿'
|
||||
'toggle8' '0.1 ◍ ◌'
|
||||
'toggle9' '0.1 ◉ ◎'
|
||||
'toggle10' '0.1 ㊂ ㊀ ㊁'
|
||||
'toggle11' '0.05 ⧇ ⧆'
|
||||
'toggle12' '0.12 ☗ ☖'
|
||||
'toggle13' '0.08 = * -'
|
||||
'arrow' '0.1 ← ↖ ↑ ↗ → ↘ ↓ ↙'
|
||||
'arrow2' '0.12 ▹▹▹▹▹ ▸▹▹▹▹ ▹▸▹▹▹ ▹▹▸▹▹ ▹▹▹▸▹ ▹▹▹▹▸'
|
||||
'bouncingBar' '0.08 "[ ]" "[ =]" "[ ==]" "[ ===]" "[====]" "[=== ]" "[== ]" "[= ]"'
|
||||
'bouncingBall' '0.08 "( ● )" "( ● )" "( ● )" "( ● )" "( ●)" "( ● )" "( ● )" "( ● )" "( ● )" "(● )"'
|
||||
'pong' '0.08 "▐⠂ ▌" "▐⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂▌" "▐ ⠠▌" "▐ ⡀▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐ ⠠ ▌" "▐ ⠂ ▌" "▐ ⠈ ▌" "▐ ⠂ ▌" "▐ ⠠ ▌" "▐ ⡀ ▌" "▐⠠ ▌"'
|
||||
'shark' '0.12 "▐|\\____________▌" "▐_|\\___________▌" "▐__|\\__________▌" "▐___|\\_________▌" "▐____|\\________▌" "▐_____|\\_______▌" "▐______|\\______▌" "▐_______|\\_____▌" "▐________|\\____▌" "▐_________|\\___▌" "▐__________|\\__▌" "▐___________|\\_▌" "▐____________|\\▌" "▐____________/|▌" "▐___________/|_▌" "▐__________/|__▌" "▐_________/|___▌" "▐________/|____▌" "▐_______/|_____▌" "▐______/|______▌" "▐_____/|_______▌" "▐____/|________▌" "▐___/|_________▌" "▐__/|__________▌" "▐_/|___________▌" "▐/|____________▌"'
|
||||
)
|
||||
|
||||
###
|
||||
# Output usage information and exit
|
||||
###
|
||||
|
|
@ -10,6 +69,7 @@ function _revolver_usage() {
|
|||
echo "\033[0;33mOptions:\033[0;m"
|
||||
echo " -h, --help Output help text and exit"
|
||||
echo " -v, --version Output version information and exit"
|
||||
echo " -s, --style Set the spinner style"
|
||||
echo
|
||||
echo "\033[0;33mCommands:\033[0;m"
|
||||
echo " start <message> Start the spinner"
|
||||
|
|
@ -27,6 +87,12 @@ function _revolver_process() {
|
|||
dir=${REVOLVER_DIR:-"${ZDOTDIR:-$HOME}/.revolver"}
|
||||
statefile="$dir/$pid"
|
||||
|
||||
# The frames that, when animated, will make up
|
||||
# our spinning indicator
|
||||
frames=(${(@z)_revolver_spinners[$style]})
|
||||
interval=${(@z)frames[1]}
|
||||
shift frames
|
||||
|
||||
# Create a never-ending loop
|
||||
while [[ 1=1 ]]; do
|
||||
# If the statefile has been removed, exit the script
|
||||
|
|
@ -53,7 +119,7 @@ function _revolver_process() {
|
|||
# Output the current spinner frame, and add a
|
||||
# slight delay before the next one
|
||||
_revolver_spin
|
||||
sleep 0.1
|
||||
sleep ${interval:-"0.1"}
|
||||
done
|
||||
}
|
||||
|
||||
|
|
@ -61,11 +127,7 @@ function _revolver_process() {
|
|||
# Output the spinner itself, along with a message
|
||||
###
|
||||
function _revolver_spin() {
|
||||
local dir statefile state pid frames
|
||||
|
||||
# The frames that, when animated, will make up
|
||||
# our spinning indicator
|
||||
frames=('⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏')
|
||||
local dir statefile state pid frame
|
||||
|
||||
# ZSH arrays start at 1, so we need to bump the index if it's 0
|
||||
if [[ $spinner_index -eq 0 ]]; then
|
||||
|
|
@ -78,13 +140,14 @@ function _revolver_spin() {
|
|||
# Echo the current frame and message, and overwrite
|
||||
# the rest of the line with white space
|
||||
msg="\033[0;38;5;242m${msg}\033[0;m"
|
||||
printf '%*.*b' ${#msg} $lim "${frames[$spinner_index]} $msg$(printf '%0.1s' " "{1..$lim})"
|
||||
frame="${${(@z)frames}[$spinner_index]//\"}"
|
||||
printf '%*.*b' ${#msg} $lim "$frame $msg$(printf '%0.1s' " "{1..$lim})"
|
||||
|
||||
# Return to the beginning of the line
|
||||
echo -n "\r"
|
||||
|
||||
# Set the spinner index to the next frame
|
||||
spinner_index=$(( $(( $spinner_index + 1 )) % ${#frames} ))
|
||||
spinner_index=$(( $(( $spinner_index + 1 )) % $(( ${#frames} + 1 )) ))
|
||||
}
|
||||
|
||||
###
|
||||
|
|
@ -179,12 +242,13 @@ function _revolver_start() {
|
|||
###
|
||||
function _revolver() {
|
||||
# Get the context from the first parameter
|
||||
local help version ctx="$1"
|
||||
local help version style ctx="$1"
|
||||
|
||||
# Parse CLI options
|
||||
zparseopts -D \
|
||||
h=help -help=help \
|
||||
v=version -version=version
|
||||
v=version -version=version \
|
||||
s:=style -style:=style
|
||||
|
||||
# Output usage information and exit
|
||||
if [[ $help ]]; then
|
||||
|
|
@ -198,6 +262,20 @@ function _revolver() {
|
|||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -z $style ]]; then
|
||||
style='dots'
|
||||
fi
|
||||
|
||||
if [[ -n $style ]]; then
|
||||
shift style
|
||||
ctx="$1"
|
||||
fi
|
||||
|
||||
if [[ -z $_revolver_spinners[$style] ]]; then
|
||||
echo $(color red "Spinner '$style' is not recognised")
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $ctx in
|
||||
start|update|stop)
|
||||
# Check if a valid command is passed,
|
||||
|
|
|
|||
Loading…
Reference in a new issue