tui.every
tui.every SEC FN [ID]
Calls FN repeatedly on a timer from the main loop.
Parameters
SEC: interval in seconds; decimals allowed (0.25). Values below0.05are raised to0.05.FN: function, called asFN ID.ID: timer id fortui.every.canceland friends. Default:FN.
Notes
- The first call happens on the next loop iteration, not after
SEC. Usetui.afterfor a delayed start. - Registering an existing
IDagain replaces that timer and resumes it if paused. Pass distinct IDs to run one function on two timers. - Timers are removed on page change. Register them again from the page’s
on_visit. - After a terminal resize every timer runs on the next iteration, so size-dependent output re-fits at once.
FNruns inside the main loop: keep it fork-free (tui.set_text,tui.sys.*). Slow work belongs intui.watch.- Everything
FNupdates (tui.update,tui.set_label, bound datasets) is drawn once, in one write, after it returns, and at most once per frame (TUI_FRAME_BUDGET_US, default 16666 = 60 fps) however many timers fire. Values that did not change are not drawn. Button and key reactions are never held to the frame budget. - A timer that is late by whole intervals loses those ticks instead of catching up, and one that ran longer than its interval rests as long as it ran. With
_TUI_PERF_TRACKING=1,tui.perf.reportshowsticks_dropped,paced_deferredand atick:IDspan per timer (the slowest one is the culprit). - Timers registered while a plugin loads are removed when that plugin is disabled.
Example
refresh_stats() {
tui.sys.cpu; tui.sys.mem
tui.set_text stats "CPU ${TUI_SYS_CPU}% MEM ${TUI_SYS_MEM_PCT}%"
}
tui.every 2 refresh_stats
See also: tui.after, tui.tick.add, tui.watch
