Skip to content
@skiffyard/clispinner

Cheatsheet

Every export of @skiffyard/clispinner. Programs import the deck once and use the spinner verbs; the catalogue module frames.j is imported by path when a program wants to validate a name before passing it.

jennifer
import "@skiffyard/clispinner/" as clispinner;
import "@skiffyard/clispinner/frames.j" as frames;

Spinner

CallReturnsDoes
clispinner.startSpinner(opts as Options)Spinnerlaunch the animating task and return at once
clispinner.statusSpinner(sp as Spinner, msg as string)Spinnerreplace the status text
clispinner.updateSpinner(sp as Spinner, opts as Options)Spinnerreplace a running spinner's options and restart at frame 0
clispinner.removeSpinner(sp as Spinner)intstop the spinner, erase its block, show the cursor; the frames drawn
clispinner.finishSpinner(sp as Spinner, mark as string, msg as string)intremoveSpinner, then write mark msg as a line that stays
clispinner.options(name as string, label as string)Optionsoptions with speed 0 and stream STDERR
clispinner.spinnerNames()list of stringevery catalogue name, sorted
clispinner.spinnerSize(name as string)Sizethe room an animation needs

Options and layout

CallReturnsDoes
clispinner.resolveOptions(opts as Options)Optionsnormalise options: known name, speed of 0 or more, a known stream
clispinner.intervalOf(opts as Options)intframe interval in ms: the speed, or the animation's own
clispinner.drawable(stream as string)boolwhether a stream is a terminal
clispinner.terminalWidth(stream as string)intterminal width in columns, or FALLBACK_COLS
clispinner.terminalHeight(stream as string)intterminal height in rows, or FALLBACK_ROWS
clispinner.visibleRows(stream as string, wanted as int)introws a spinner may draw: the window height minus one at most
clispinner.frameRows(frame as string)list of stringsplit a frame on \n
clispinner.clipFrame(frame as string, maxRows as int)stringkeep the first maxRows rows of a frame
clispinner.fitStatus(status as string, budget as int)stringtrim text to budget runes, a cut ending in …
clispinner.wrapHard(text as string, width as int)list of stringbreak text into chunks of at most width runes, mid-word
clispinner.layoutStatus(status as string, rows as int, width as int)list of stringlay a status out in at most rows lines of width runes
clispinner.renderBlock(frame as string, status as string, frameCols as int, width as int)stringcompose a frame and its status into a block that does not wrap
clispinner.renderLine(frame as string, status as string)stringframe, a space, status; no width limit or erase sequence

Control sequences

CallReturnsDoes
clispinner.eraseLine()stringerase the current line, cursor to its start
clispinner.eraseBlock(rows as int)stringerase the last rows lines, cursor at the start of the topmost
clispinner.hideCursor()stringhide the cursor
clispinner.showCursor()stringshow the cursor

The animating task's state

Exported so the tests drive the state machine without a terminal.

CallReturnsDoes
clispinner.newState(opts as Options)Stateframe 0, nothing drawn, status set to the label
clispinner.applyCommand(st as State, c as Command)Stateapply one command
clispinner.currentFrame(st as State)stringthe frame to draw next
clispinner.advance(st as State, counted as bool)Statemove to the next frame, counting it in drawn when counted
clispinner.drewRows(st as State, rows as int)Staterecord the rows just written, for the next erase

The catalogue (frames.j)

CallReturnsDoes
frames.names()list of stringevery catalogue name, sorted
frames.has(name as string)boolwhether the catalogue has the name
frames.get(name as string)Framesan animation by name, DEFAULT_NAME's when unknown; never throws

Constants

ConstantvalueIs
clispinner.STDOUT"stdout"stream name for standard output
clispinner.STDERR"stderr"stream name for standard error, the default
clispinner.FALLBACK_COLS80width assumed when the real one cannot be read
clispinner.FALLBACK_ROWS24height assumed when the real one cannot be read
frames.DEFAULT_NAME"dots"the animation get returns for an unknown name

Types

Options

How a spinner looks and where it writes. Build one with options.

  • name as string: catalogue name; unknown or "" falls back to dots
  • speed as int: frame interval in ms; 0 or less uses the animation's own
  • label as string: initial status text
  • stream as string: STDOUT or STDERR; anything else means STDERR

Spinner

Handle to a running spinner.

  • commands as channel of Command: the queue the task reads
  • worker as task of int: the animating task; yields the frame count
  • options as Options: the resolved options last sent to the task

Command

One instruction to a running spinner.

  • kind as string: "stop", "status" or "update"; other kinds are ignored
  • text as string: new status text, for "status"
  • options as Options: new options, for "update"

State

The animating task's state.

  • options as Options: the resolved options
  • spec as frames.Frames: the animation the options select
  • status as string: text beside the spinner
  • index as int: next frame to draw, not wrapped
  • drawn as int: frames written
  • rows as int: lines the block on screen occupies, for the next erase
  • stopped as bool: whether a stop command has arrived

Size

Room an animation needs.

  • cols as int: terminal columns every frame occupies
  • rows as int: lines every frame occupies

Frames

One named animation and the box it draws in (frames.j).

  • name as string: catalogue name
  • interval as int: design frame interval in milliseconds
  • cols as int: terminal columns every frame occupies, after padding
  • rows as int: lines every frame occupies; 12 for soccerVertical, else 1
  • frames as list of string: the frames, in order