Skip to main content

run

Function run 

Source
pub async fn run(
    app: TuiApp,
    bus: EventBus,
    bus_rx: Receiver<Event>,
    cancel: CancellationToken,
    profile_path: Option<PathBuf>,
    profile: Profile,
) -> Result<()>
Expand description

Drive the TUI main loop until cancelled or the user requests quit.

Owns the ratatui terminal + crossterm event stream; restores cooked mode + leaves the alternate screen on return (including on Err).

§Parameters

  • app — the prepared TuiApp; caller seeds device summary, initial SerialConfig, line endings, modem lines, and modal style before handing in.
  • bus — the shared EventBus, used to publish Event::TxBytes for keystrokes and Event::ProfileSaved / Event::ProfileLoadFailed for profile-IO outcomes.
  • bus_rx — a pre-subscribed bus receiver; subscribe before spawning the session task so no events are missed.
  • cancel — the shared CancellationToken. Tripping it (via signal, session exit, or Dispatch::Quit) unwinds the loop.
  • profile_path — where to read/write the profile TOML when the user triggers a save-flavored dialog action. None when no path is discoverable (tests, $HOME-less CI); save actions become no-ops + tracing::warn in that case.
  • profile — the currently-loaded profile, owned by the run loop. Mutated in place when ApplyAndSave / ApplyModalStyleAndSave / ReadProfile rewrite sections; persisted on disk through rtcom_config::write.

§Errors

Propagates terminal setup, IO, and render errors. Bus Lagged warnings are logged and the loop continues; a bus Closed error is treated as an implicit cancel and the function returns Ok(()).