hwylterm/spin

Source   Edit  

spin

Animated terminal spinner backed by a background thread. The simplest usage is the withSpinner template, which starts the spinner, runs a block, then stops it automatically.

import std/os
import hwylterm/spin

withSpinner("loading..."):
  sleep 2000

Use spinner.setText inside the block to update the message while running:

import std/os
import hwylterm/spin

withSpinner("step 1"):
  sleep 500
  spinner.setText("step 2")
  sleep 500
  spinner.setText("done")
  sleep 500

To pick a specific spinner style, use the with template:

import std/os
import hwylterm/spin

Moon.with("loading..."):
  sleep 2000

See spinners: SpinnerKind for all available styles.

Types

Spinny = ref object
  symbolPad*: Natural
Source   Edit  

Procs

proc echo(spinny: Spinny; text: string | BbString)
Source   Edit  
proc newSpinny(text: BbString; s: Spinner): Spinny {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc newSpinny(text: string | BbString = "";
               spinType: SpinnerKind = defaultSpinnerKind): Spinny
Source   Edit  
proc newSpinny(text: string; s: Spinner): Spinny {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc running(s: Spinny): bool {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc setSymbol(spinny: Spinny; symbol: string) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc setSymbolColor(spinny: Spinny; style: string) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc setText(spinny: Spinny; text: string | BbString)
Source   Edit  
proc start(spinny: Spinny) {....raises: [IOError, ResourceExhaustedError],
                             tags: [WriteIOEffect], forbids: [].}
Source   Edit  
proc stop(spinny: Spinny) {....raises: [IOError], tags: [WriteIOEffect],
                            forbids: [].}
Source   Edit  

Templates

template useSpinner(spinner: Spinny; body: untyped)
Source   Edit  
template with(kind: SpinnerKind; msg: BbString; body: untyped): untyped
Source   Edit  
template with(kind: SpinnerKind; msg: string; body: untyped): untyped
Source   Edit  
template withSpinner(body: untyped): untyped
Source   Edit  
template withSpinner(msg: BbString = bb""; body: untyped): untyped
Source   Edit  
template withSpinner(msg: string = ""; body: untyped): untyped
Source   Edit