Skip to main content

hyprstream_tui/
container_app.rs

1//! ContainerTermApp — read-only terminal for container stdout attach.
2//!
3//! Displays container output in a VT pane. Used by the AttachContainer
4//! RPC handler (Phase W-III-a). Stdin forwarding (Phase W-III-b) is
5//! stubbed via `VtPane::send_bytes`.
6
7#![cfg(not(target_os = "wasi"))]
8
9use ratatui::Frame;
10use waxterm::app::TerminalApp;
11use waxterm::input::KeyPress;
12
13use crate::vt_pane::VtPane;
14
15/// A terminal app that displays container stdout via a `VtPane`.
16pub struct ContainerTermApp {
17    pub pane: VtPane,
18    pub container_id: String,
19    pub sandbox_id: String,
20    pub cols: u16,
21    pub rows: u16,
22    pub quit: bool,
23    pub pending_toasts: Vec<String>,
24}
25
26impl ContainerTermApp {
27    pub fn new(
28        container_id: String,
29        sandbox_id: String,
30        cols: u16,
31        rows: u16,
32        stdout_rx: std::sync::mpsc::Receiver<Vec<u8>>,
33        stdin_tx: Option<std::sync::mpsc::SyncSender<Vec<u8>>>,
34    ) -> Self {
35        Self {
36            pane: VtPane::new(cols, rows, stdout_rx, stdin_tx),
37            container_id,
38            sandbox_id,
39            cols,
40            rows,
41            quit: false,
42            pending_toasts: Vec::new(),
43        }
44    }
45}
46
47impl TerminalApp for ContainerTermApp {
48    type Command = KeyPress;
49
50    fn render(&self, frame: &mut Frame) {
51        let area = frame.area();
52        hyprstream_compositor::render::draw_vt_cells(frame, area, &self.pane.vt);
53    }
54
55    fn handle_input(&mut self, key: KeyPress) -> bool {
56        // Phase W-III-b: forward key bytes via pane.send_bytes()
57        let bytes = hyprstream_compositor::keypress_to_bytes(key);
58        if !bytes.is_empty() {
59            self.pane.send_bytes(bytes);
60        }
61        false
62    }
63
64    fn tick(&mut self, _delta_ms: u64) -> bool {
65        let (got_data, is_dead) = self.pane.drain();
66        if is_dead {
67            self.quit = true;
68        }
69        got_data
70    }
71
72    fn should_quit(&self) -> bool {
73        self.quit
74    }
75}