beamtea_timer (beamtea v0.1.2)
View SourceA bubble: a countdown timer, mirroring the timer package in charmbracelet/bubbles.
Like the spinner, it keeps itself running by re-scheduling its own tick. Start it with start/1 from init/1 (or on a key), forward messages to update/2, and check timed_out/1 to react to expiry.
T = beamtea_timer:new(#{timeout_ms => 10000}),
{#st{timer = T}, beamtea_timer:start(T)}.
Summary
Functions
Options: timeout_ms (required-ish, default 60000), interval_ms (tick granularity, default 1000).
Start (or resume) counting down; returns the command that schedules the first tick.
Pause/resume. Returns the (possibly re-armed) command.
Advance on the timer's own tick; ignore other messages.
Render the remaining time as MM:SS.
Types
Functions
Options: timeout_ms (required-ish, default 60000), interval_ms (tick granularity, default 1000).
-spec start(model()) -> beamtea:cmd().
Start (or resume) counting down; returns the command that schedules the first tick.
-spec toggle(model()) -> {model(), beamtea:cmd()}.
Pause/resume. Returns the (possibly re-armed) command.
-spec update(term(), model()) -> {model(), beamtea:cmd()}.
Advance on the timer's own tick; ignore other messages.
Render the remaining time as MM:SS.