letiul/spin

threaded terminal spinners for lune

spin

Threaded terminal spinners for the Lune Runtime.

Warning

This might not work as intended for all terminals for several reasons. This includes utf8 characters for some animations provided by the package and possibly ANSI escape characters.

The animations are handled in the current cursor position and wont update inplace when there are other write statements happening in parallel.

Installation

pesde add letiul/spin

Examples

Creating a spin

local spin = require('@pkg/spin')

local stop = spin.create(spin.animations.arc) -- setting the argument to 'nil' will use animations.slash by default
-- ... [do stuff that yields or takes time]
stop() -- stops the spin and clears it from the terminal.

Spinning while on a interval

local spin = require('@pkg/spin')

-- this
local stop = spin.create()
task.wait(1)
stop()

-- is the same as this
spin.interval(nil, 1)

Awaiting a function to complete

local stdio = require('@lune/stdio')
local spin = require('@pkg/spin')

stdio.write("loading... ")
spin.await(spin.animations.line, function()
    task.wait(1.5)
end)
stdio.write("done!\n")

Custom spinners

local spin = require('@pkg/spin')

local anim = {
    interval = 90, -- in miliseconds
    frames = {
        "1",
        "2",
        "3",
        "4",
        "5",
    }
}

spin.interval(anim, 1)

Contribuiting

It's always a headache (atleast for me) when dealing with terminal tools. Any issues and pull requests to improve or fix the code are greatly appreciated.

Credits

All of the default spinners (in other words, the animations.luau file or the animations table in the library) were adapted from the package cli-spinners, originally for JS.