tui.async.start
tui.async.start NAME FN [ARG...]
Forks FN with ARG… into the background as a painter: a function running in its own process that paints directly to the terminal with absolute cursor moves, so its frames cost the main loop nothing.
Parameters
NAME: identifier for this painter. A secondstartwith the same NAME kills the first.FN: the function to run.ARG...: arguments passed to FN.
Notes
- The painter runs with the process’s own copy of the page state as it was at fork time, and its stdin is
/dev/null. - The painter process is trapped to exit cleanly on TERM, HUP and INT signals.
- The parent process id is stored in
_TUI_ASYNC_PARENT; a painter can checkkill -0 "$_TUI_ASYNC_PARENT"to detect when the main process is gone and exit itself. - Painters are stopped by
tui.async.stop,tui.async.stop_all, and automatically on app exit.
Example
counter_painter() {
local count=0
while kill -0 "$_TUI_ASYNC_PARENT" 2>/dev/null; do
tui.async.get "counter.count" count
count=${count:-0}
printf '\e[2;5H%d' "$count"
tui.async.wait 0.1
done
}
# Start the painter
tui.async.start counter counter_painter
# In the main loop: update the counter
tui.async.put counter count 5
See also
