rayvn/spinner
Terminal spinners.
Functions
spinnerTypes()
Populates an array with the names of all available spinner types.
args
resultArray (arrayRef) | Array to populate with spinner type names. |
example
local types
spinnerTypes types
echo "Available: ${types[*]}"
startSpinner()
Start a spinner at the current cursor position, storing its assigned ID via nameref.
args
idVarName (stringRef) | Name of var holding the spinner ID (from startSpinner). |
label (string) | Optional text displayed before the spinner. |
type (string) | Spinner type (default: ‘star’). |
color (string) | Color name (default: ‘secondary’). |
example
local spinnerId
startSpinner spinnerId "Loading" dots primary
doWork
stopSpinner spinnerId "Done"
stopSpinner()
Stop a spinner, optionally replacing it with the given text.
args
idVarName (stringRef) | Name of var holding the spinner ID (from startSpinner). |
replacement (string) | Text to display in place of the spinner (default: space). |
notes
The -n flag suppresses the trailing newline, as in echo -n.
example
stopSpinner spinnerId "Done"
stopSpinner -n spinnerId
addSpinner()
Add a spinner at a specific terminal position, storing its assigned id via nameref.
args
idRef (stringRef) | Name of var to receive the spinner id. |
type (string) | Spinner type. |
row (int) | Terminal row (1-based). |
col (int) | Terminal column (1-based). |
color (string) | Color name for the spinner (default: ‘secondary’). |
removeSpinner()
Remove a spinner by id; prefer stopSpinner for typical use.
args
idVarName (stringRef) | Name of var holding the spinner id (from addSpinner). |
replacement (string) | Text to display in place of the spinner (default: space). |
newline (bool) | Emit a newline after replacement (default: true). |
backup (int) | Characters to back up before writing replacement (default: 0). |
spinnerCloseInheritedFds()
Close the inherited spinner client fds in a subshell forked from the spinner owner. Call this at the start of any ( ) & subshell that inherits these fds, to prevent accidental writes that would corrupt the spinner FIFO protocol.