Skip to main content

rpi_cli/remote/
tui.rs

1//! `rpi --connect`: connect a [`RemoteDriver`] and run the shared TUI shell.
2//!
3//! This module is the remote **adapter** only — the shell it drives lives in
4//! [`crate::tui_shell`], and the transport lives in
5//! [`crate::session_driver::RemoteDriver`].
6
7use crate::app::EXIT_RUNTIME;
8use crate::session_driver::RemoteDriver;
9use crate::tui_shell::run_driver_tui;
10
11/// Connect to a server and run the interactive client until the user exits.
12pub async fn run(addr: &str, token: Option<&str>) -> i32 {
13    let driver = match RemoteDriver::connect(addr, token).await {
14        Ok(driver) => driver,
15        Err(error) => {
16            eprintln!("error: {error}");
17            return EXIT_RUNTIME;
18        }
19    };
20    let code = match run_driver_tui(&driver, addr).await {
21        Ok(()) => 0,
22        Err(error) => {
23            eprintln!("error: {error}");
24            EXIT_RUNTIME
25        }
26    };
27    driver.shutdown().await;
28    code
29}