Something went wrong. Try again.
minimal agent cli memoria.tools
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081package tea
// Countdown timer. Tick-driven: the app forwards its Tick event and decides// the delta, so the component stays deterministic in tests.
import "core:fmt"import "core:time"
Timer :: struct { duration: time.Duration, remaining: time.Duration, running: bool, finished: bool,}
timer_make :: proc(duration: time.Duration) -> Timer { d := max(0, duration) return Timer { duration = d, remaining = d, running = d > 0, finished = d == 0, }}
timer_start :: proc(t: ^Timer) -> bool { t.remaining = t.duration t.running = t.duration > 0 t.finished = t.duration == 0 return t.duration > 0}
timer_stop :: proc(t: ^Timer) -> bool { if !t.running { return false } t.running = false return true}
timer_toggle :: proc(t: ^Timer) -> bool { if t.running { return timer_stop(t) } return timer_start(t)}
timer_reset :: proc(t: ^Timer) -> bool { changed := t.remaining != t.duration || t.running || t.finished t.remaining = t.duration t.running = false t.finished = false return changed}
timer_tick :: proc(t: ^Timer, delta: time.Duration) -> bool { if !t.running || delta <= 0 { return false } t.remaining -= delta if t.remaining <= 0 { t.remaining = 0 t.running = false t.finished = true } return true}
timer_view :: proc(t: ^Timer) -> string { ns := max(i64(0), time.duration_nanoseconds(t.remaining)) seconds := (ns + 999_999_999) / 1_000_000_000 hours := seconds / 3600 minutes := (seconds % 3600) / 60 secs := seconds % 60
if hours > 0 { return fmt.tprintf("%d:%02d:%02d", hours, minutes, secs) } return fmt.tprintf("%02d:%02d", minutes, secs)}