term.gfx.loop — Lilush API

←index

← term.gfx

Overview

Frame loop — a fixed-timestep animation/game loop on the LEV runtime.

Generalizes the matrix rain's hand-rolled lev.spawn loop into a reusable harness: a render task drives a fixed-step clock (decoupling simulation rate from the variable wall-clock frame time, with a spiral-of-death clamp), while a separate input task reads keys cooperatively via term.read_key over a lev.fd_reader — the proven pattern from the shell's input handling. Both tasks share one cancel token so stop() tears the whole thing down at once.

Two entry points:

Terminals have no vsync, so the loop paces with lev.sleep and exposes the measured fps_actual.

Functions

NameSignature
tickerticker(fps) -> ticker
looploop(opts) -> handle

ticker(fps) -> ticker

Create a frame ticker for a custom loop

Returns { step = <seconds>, tick = fn }.

Each ticker:tick() sleeps until the next frame boundary and returns the delta time (seconds) since the previous tick.

Use it when you want to drive your own loop body rather than hand callbacks to loop.

loop(opts) -> handle

Create a fixed-timestep frame loop

opts:

Handle: