pub async fn event_loop<B, M>(
terminal: &mut Terminal<B>,
model: M,
rx: UnboundedReceiver<ReplEvent>,
apply: impl FnMut(&mut M, ReplEvent),
render: impl FnMut(&mut Frame<'_>, &M),
) -> Result<M>Expand description
The terminal-generic tick/event select loop.
Why: split out from run specifically so it can be exercised in tests
against ratatui::backend::TestBackend — run itself requires a real
TTY (via TerminalGuard::enter) and so cannot run in CI/sandboxes.
What: draws once immediately, then loops a biased tokio::select! between
the TICK interval (redraw only) and rx.recv() (apply the event via
apply, then redraw). Exits when model.should_quit() becomes true or
rx closes (all senders dropped — mirrors
crates/trusty-agents/src/repl/tui/run.rs::event_loop’s None => return Ok(())). Returns the final model so callers/tests can inspect it.
Test: tests::event_loop_applies_events_and_redraws,
tests::event_loop_stops_when_model_requests_quit,
tests::event_loop_stops_when_channel_closes,
tests::event_loop_redraws_on_tick_even_without_events.