Skip to main content

hyprstream_core/tui/
shell_client.rs

1//! RPC helpers for the ShellClient TUI.
2//!
3//! Thin wrappers around generated `TuiClient` typed methods for ergonomic
4//! call-site usage: spawnShell, pollStdin, focusWindow, spawnChatApp, closeWindow.
5
6use hyprstream_rpc_std::tui_client::{SpawnChatAppRequest, SpawnShellRequest, TuiClient};
7
8/// Send a spawnShell RPC to TuiService.
9pub async fn spawn_shell_rpc(
10    client: &TuiClient,
11    session_id: u32,
12    pane_id: u32,
13    cwd: &str,
14) -> anyhow::Result<()> {
15    let _ = client
16        .spawn_shell(&SpawnShellRequest {
17            session_id,
18            pane_id,
19            cwd: cwd.to_owned(),
20        })
21        .await?;
22    Ok(())
23}
24
25/// Poll for stdin bytes queued for this viewer (pollStdin RPC).
26pub async fn poll_stdin_rpc(client: &TuiClient, viewer_id: u32) -> anyhow::Result<Vec<u8>> {
27    client.poll_stdin(viewer_id).await
28}
29
30/// Tell TuiService which window is active for this session.
31pub async fn focus_window_rpc(client: &TuiClient, window_id: u32) -> anyhow::Result<()> {
32    client.focus_window(window_id).await
33}
34
35/// Send a spawnChatApp RPC to TuiService.
36pub async fn spawn_chat_app_rpc(
37    client: &TuiClient,
38    session_id: u32,
39    model_ref: &str,
40    cols: u16,
41    rows: u16,
42    pane_id: u32,
43) -> anyhow::Result<()> {
44    let _ = client
45        .spawn_chat_app(&SpawnChatAppRequest {
46            session_id,
47            model_ref: model_ref.to_owned(),
48            cols,
49            rows,
50            pane_id,
51        })
52        .await?;
53    Ok(())
54}
55
56/// Close a window by ID via RPC.
57pub async fn close_window_rpc(client: &TuiClient, window_id: u32) -> anyhow::Result<()> {
58    client.close_window(window_id).await
59}