Launch the `OpenShell` TUI. `channel` must be a connected gRPC channel to the `OpenShell` gateway. `theme_mode` selects the color theme: `Auto` detects the terminal background, `Dark`/`Light` forces a specific palette.
(
channel: Channel,
interceptor: EdgeAuthInterceptor,
gateway_name: &str,
endpoint: &str,
theme_mode: ThemeMode,
)
| 43 | /// `theme_mode` selects the color theme: `Auto` detects the terminal |
| 44 | /// background, `Dark`/`Light` forces a specific palette. |
| 45 | pub async fn run( |
| 46 | channel: Channel, |
| 47 | interceptor: EdgeAuthInterceptor, |
| 48 | gateway_name: &str, |
| 49 | endpoint: &str, |
| 50 | theme_mode: ThemeMode, |
| 51 | ) -> Result<()> { |
| 52 | // Detect theme *before* entering raw/alternate-screen mode. |
| 53 | // The OSC 11 query temporarily enters raw mode itself; calling it |
| 54 | // after our own enable_raw_mode() would conflict. |
| 55 | let detected_theme = theme::detect(theme_mode); |
| 56 | |
| 57 | let client = OpenShellClient::with_interceptor(channel, interceptor); |
| 58 | let mut app = App::new( |
| 59 | client, |
| 60 | gateway_name.to_string(), |
| 61 | endpoint.to_string(), |
| 62 | detected_theme, |
| 63 | ); |
| 64 | |
| 65 | enable_raw_mode().into_diagnostic()?; |
| 66 | let mut stdout = io::stdout(); |
| 67 | execute!(stdout, EnterAlternateScreen, EnableMouseCapture).into_diagnostic()?; |
| 68 | |
| 69 | let backend = CrosstermBackend::new(stdout); |
| 70 | let mut terminal = Terminal::new(backend).into_diagnostic()?; |
| 71 | terminal.clear().into_diagnostic()?; |
| 72 | |
| 73 | let mut events = EventHandler::new(Duration::from_secs(2)); |
| 74 | |
| 75 | refresh_gateway_list(&mut app); |
| 76 | refresh_data(&mut app).await; |
| 77 | |
| 78 | while app.running { |
| 79 | terminal |
| 80 | .draw(|frame| ui::draw(frame, &mut app)) |
| 81 | .into_diagnostic()?; |
| 82 | |
| 83 | match events.next().await { |
| 84 | Some(Event::Key(key)) => { |
| 85 | app.handle_key(key); |
| 86 | // Handle async actions triggered by key presses. |
| 87 | if app.pending_gateway_switch.is_some() { |
| 88 | handle_gateway_switch(&mut app).await; |
| 89 | } |
| 90 | if app.pending_log_fetch { |
| 91 | app.pending_log_fetch = false; |
| 92 | spawn_log_stream(&mut app, events.sender()); |
| 93 | } |
| 94 | if app.pending_sandbox_delete { |
| 95 | app.pending_sandbox_delete = false; |
| 96 | handle_sandbox_delete(&mut app).await; |
| 97 | } |
| 98 | if app.pending_create_sandbox { |
| 99 | app.pending_create_sandbox = false; |
| 100 | spawn_create_sandbox(&mut app, events.sender()); |
| 101 | start_anim_ticker(&mut app, events.sender()); |
| 102 | } |
no test coverage detected