MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / run

Function run

crates/openshell-tui/src/lib.rs:45–436  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

43/// `theme_mode` selects the color theme: `Auto` detects the terminal
44/// background, `Dark`/`Light` forces a specific palette.
45pub 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 }

Callers 1

mainFunction · 0.50

Calls 15

detectFunction · 0.85
refresh_gateway_listFunction · 0.85
refresh_dataFunction · 0.85
handle_gateway_switchFunction · 0.85
spawn_log_streamFunction · 0.85
handle_sandbox_deleteFunction · 0.85
spawn_create_sandboxFunction · 0.85
start_anim_tickerFunction · 0.85
spawn_create_providerFunction · 0.85
spawn_get_providerFunction · 0.85
spawn_update_providerFunction · 0.85
spawn_delete_providerFunction · 0.85

Tested by

no test coverage detected