Module terminal.progress
A module for progress updating.
Functions
spinner (opts) | Create a progress spinner. |
ticker (text[, width=40[, text_done=""]]) | Create a text/led ticker like sprite-sequence for use with a progress spinner. |
Fields
sprites | table with predefined sprites for progress spinners. |
Functions
- spinner (opts)
-
Create a progress spinner.
The returned spinner function can be called as often as needed to update the spinner. It will only update after
the
stepsize
has passed since the last update. So try to call it at least everystepsize
seconds, or more often. Ifrow
andcol
are given then terminal memory is used to (re)store the cursor position. If they are not given then the spinner will be printed at the current cursor position, and the cursor will return to the same position after each update.Parameters:
- opts a table of options;
- sprites table a table of strings to display, one at a time, overwriting the previous one. Index 0 is the "done" message. See sprites for a table of predefined sprites.
- stepsize number the time in seconds between each step (before printing the next string from the sequence) (default 0.2)
- textattr textattr a table of text attributes to apply to the text (using the stack), or nil to not change the attributes.
- done_textattr textattr a table of text attributes to apply to the "done" message, or nil to not change the attributes. (optional)
- done_sprite
string
the sprite to display when the spinner is done. This overrides
sprites[0]
if provided. (optional) - row
number
the row to print the spinner (required if
col
is provided) (optional) - col
number
the column to print the spinner (required if
row
is provided) (optional)
Returns:
-
function
a stepper function that should be called in a loop to update the spinner. Signature:
nil = stepper(done)
wheredone
is a boolean indicating that the spinner should print the "done" message. - opts a table of options;
- ticker (text[, width=40[, text_done=""]])
-
Create a text/led ticker like sprite-sequence for use with a progress spinner.
Parameters:
- text string the text to display
- width number the width of the ticker, in characters (default 40)
- text_done string the text to display when the spinner is done (default "")
Returns:
-
table
a table of sprites to use with a spinner
Fields
- sprites
-
table with predefined sprites for progress spinners. The sprites are tables of strings, where each string is a frame in the spinner animation. The frame at index 0 is optional and is the "done" message, the rest are the animation frames.
Available pre-defined spinners are:
bar_vertical
- a vertical bar that grows from the bottom to the topbar_horizontal
- a horizontal bar that grows from left to rightsquare_rotate
- a square that rotates clockwisemoon
- a moon that waxes and wanesdot_expanding
- a dot that expands and contractsdot_vertical
- a dot that moves up and downdot1_snake
- a dot that moves in a snake-like patterndot2_snake
- 2 dots that move in a snake-like patterndot3_snake
- 3 dots that move in a snake-like patterndot4_snake
- 4 dots that move in a snake-like patternblock_pulsing
- a block that pulses in transparencybar_rotating
- a bar that rotates clockwise- spinner - a spinner that rotates clockwise
dot_horizontal
- 3 dots growing from left to right