Skip to main content

rmux_core/
terminal_screen.rs

1//! Public live-terminal screen facade.
2//!
3//! This module exposes the server-facing screen wrapper while keeping the
4//! parser implementation inside the crate-private `terminal` module.
5
6use rmux_proto::TerminalSize;
7
8use crate::screen::Screen;
9use crate::terminal::TerminalParser;
10use crate::utf8::Utf8Config;
11
12/// Live terminal screen fed by rmux-core's private parser boundary.
13///
14/// `TerminalScreen` is the public core facade that server code uses to feed
15/// raw PTY bytes and inspect structured screen cells. The parser itself stays
16/// hidden behind the crate-private terminal module, so SDK/protocol code can
17/// depend on screen-cell semantics without coupling to parser internals.
18pub struct TerminalScreen {
19    parser: TerminalParser,
20}
21
22impl TerminalScreen {
23    /// Builds a fresh terminal screen with the given geometry and scrollback
24    /// limit.
25    #[must_use]
26    pub fn new(size: TerminalSize, history_limit: usize) -> Self {
27        Self {
28            parser: TerminalParser::new(size, history_limit),
29        }
30    }
31
32    /// Returns a borrow of the structured screen grid.
33    #[must_use]
34    pub fn screen(&self) -> &Screen {
35        self.parser.screen()
36    }
37
38    /// Returns a mutable borrow of the structured screen grid.
39    pub fn screen_mut(&mut self) -> &mut Screen {
40        self.parser.screen_mut()
41    }
42
43    /// Updates the tmux-style UTF-8 width and combining configuration.
44    pub fn set_utf8_config(&mut self, config: Utf8Config) {
45        self.parser.set_utf8_config(config);
46    }
47
48    /// Resizes the screen and resets the scroll region.
49    pub fn resize(&mut self, size: TerminalSize) {
50        self.parser.resize(size);
51    }
52
53    /// Feeds raw PTY output bytes through the private parser into the screen.
54    pub fn feed(&mut self, bytes: &[u8]) {
55        self.parser.feed(bytes);
56    }
57
58    /// Returns any bytes still buffered inside an incomplete parser state.
59    #[must_use]
60    pub fn pending_bytes(&self) -> Vec<u8> {
61        self.parser.pending_bytes()
62    }
63
64    /// Replaces the hidden parser with a fresh ground-state instance while
65    /// preserving the current screen grid.
66    pub fn reset_parser(&mut self) {
67        self.parser.reset_parser();
68    }
69}