beamtea_timer (beamtea v0.1.2)

View Source

A 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

model/0

-opaque model()

Functions

new(Opts)

-spec new(map()) -> model().

Options: timeout_ms (required-ish, default 60000), interval_ms (tick granularity, default 1000).

remaining_ms(_)

-spec remaining_ms(model()) -> integer().

running(_)

-spec running(model()) -> boolean().

start(_)

-spec start(model()) -> beamtea:cmd().

Start (or resume) counting down; returns the command that schedules the first tick.

timed_out(_)

-spec timed_out(model()) -> boolean().

toggle(M)

-spec toggle(model()) -> {model(), beamtea:cmd()}.

Pause/resume. Returns the (possibly re-armed) command.

update(Msg, M)

-spec update(term(), model()) -> {model(), beamtea:cmd()}.

Advance on the timer's own tick; ignore other messages.

view(_)

-spec view(model()) -> iodata().

Render the remaining time as MM:SS.