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::terminal_passthrough::TerminalPassthrough;
11use crate::utf8::Utf8Config;
12
13/// Live terminal screen fed by rmux-core's private parser boundary.
14///
15/// `TerminalScreen` is the public core facade that server code uses to feed
16/// raw PTY bytes and inspect structured screen cells. The parser itself stays
17/// hidden behind the crate-private terminal module, so SDK/protocol code can
18/// depend on screen-cell semantics without coupling to parser internals.
19pub struct TerminalScreen {
20 parser: TerminalParser,
21}
22
23impl TerminalScreen {
24 /// Builds a fresh terminal screen with the given geometry and scrollback
25 /// limit.
26 #[must_use]
27 pub fn new(size: TerminalSize, history_limit: usize) -> Self {
28 Self {
29 parser: TerminalParser::new(size, history_limit),
30 }
31 }
32
33 /// Returns a borrow of the structured screen grid.
34 #[must_use]
35 pub fn screen(&self) -> &Screen {
36 self.parser.screen()
37 }
38
39 /// Returns a mutable borrow of the structured screen grid.
40 pub fn screen_mut(&mut self) -> &mut Screen {
41 self.parser.screen_mut()
42 }
43
44 /// Updates the tmux-style UTF-8 width and combining configuration.
45 pub fn set_utf8_config(&mut self, config: Utf8Config) {
46 self.parser.set_utf8_config(config);
47 }
48
49 /// Enables or disables DEC alternate-screen entry for subsequent output.
50 pub fn set_alternate_screen_enabled(&mut self, enabled: bool) {
51 self.parser.set_alternate_screen_enabled(enabled);
52 }
53
54 /// Enables or disables title changes requested by pane output.
55 pub fn set_title_rename_enabled(&mut self, enabled: bool) {
56 self.parser.set_title_rename_enabled(enabled);
57 }
58
59 /// Updates the tmux `input-buffer-size` parser limit.
60 pub fn set_input_buffer_limit(&mut self, limit: usize) {
61 self.parser.set_input_buffer_limit(limit);
62 }
63
64 /// Resizes the screen and resets the scroll region.
65 pub fn resize(&mut self, size: TerminalSize) {
66 self.parser.resize(size);
67 }
68
69 /// Feeds raw PTY output bytes through the private parser into the screen.
70 pub fn feed(&mut self, bytes: &[u8]) {
71 self.parser.feed(bytes);
72 }
73
74 /// Returns and drains terminal replies generated while parsing PTY output.
75 pub fn take_replies(&mut self) -> Vec<u8> {
76 self.parser.take_replies()
77 }
78
79 /// Returns any bytes still buffered inside an incomplete parser state.
80 #[must_use]
81 pub fn pending_bytes(&self) -> Vec<u8> {
82 self.parser.pending_bytes()
83 }
84
85 /// Returns and drains passthrough events generated while parsing PTY output.
86 pub fn take_terminal_passthrough(&mut self) -> Vec<TerminalPassthrough> {
87 self.parser.take_terminal_passthrough()
88 }
89
90 /// Returns and drains passthrough events dropped by parser safety limits.
91 pub fn take_terminal_passthrough_dropped_count(&mut self) -> u64 {
92 self.parser.take_terminal_passthrough_dropped_count()
93 }
94
95 /// Replaces the hidden parser with a fresh ground-state instance while
96 /// preserving the current screen grid.
97 pub fn reset_parser(&mut self) {
98 self.parser.reset_parser();
99 }
100}