A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(mux): read a pane's screen rows in one hold
RoversXc0eed2723e0c
diff --git a/mux/src/localpane.rs b/mux/src/localpane.rsindex 90155f7a..87f76864 100644--- a/mux/src/localpane.rs+++ b/mux/src/localpane.rs@@ -461,6 +461,10 @@ impl Pane for LocalPane {crate::pane::impl_get_lines_via_with_lines(self, lines)}+ fn get_screen_lines(&self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>) {+ terminal_get_screen_lines(&mut self.terminal.lock(), lines)+ }+fn get_logical_lines(&self, lines: Range<StableRowIndex>) -> Vec<LogicalLine> {crate::pane::impl_get_logical_lines_via_get_lines(self, lines)}@@ -2126,6 +2130,35 @@ mod summary_tests {drop(guard);}+ /// The alternate screen numbers its rows from nought, so bounds taken+ /// on it name the primary screen's oldest history once the program+ /// has left it. Rows held to the screen are read with the screen.+ #[test]+ fn rows_held_to_the_screen_are_read_with_it() {+ let (pane, _sizes, _exit) = pane();+ let feed = |text: &str| {+ let mut parser = termwiz::escape::parser::Parser::new();+ let mut actions = vec![];+ parser.parse(text.as_bytes(), |action| actions.push(action));+ pane.perform_actions(actions);+ };+ for row in 0..60 {+ feed(&format!("history {row}\r\n"));+ }+ feed("\x1b[?1049hfull screen");+ let alt = pane.get_dimensions();+ let asked = alt.physical_top..alt.physical_top + alt.viewport_rows as StableRowIndex;+ let (_, lines) = pane.get_screen_lines(asked.clone());+ assert!(lines[0].as_str().starts_with("full screen"));++ // The program leaves its screen between the bounds and the rows.+ feed("\x1b[?1049l");+ let (_, unheld) = pane.get_lines(asked.clone());+ assert!(unheld[0].as_str().starts_with("history 0"));+ let (_, held) = pane.get_screen_lines(asked);+ assert!(held.is_empty());+ }+#[cfg(unix)]#[test]fn program_status_keeps_the_process_group_observed_by_the_parser() {diff --git a/mux/src/pane.rs b/mux/src/pane.rsindex ba071292..dd0ab5fa 100644--- a/mux/src/pane.rs+++ b/mux/src/pane.rs@@ -301,6 +301,21 @@ pub trait Pane: Downcast + Send + Sync {/// the first row in the range.fn get_lines(&self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>);+ /// `get_lines`, held to the rows on the screen as they are read. The+ /// screen's bounds and its rows are read together: the two screens+ /// number their rows apart, so bounds read before a switch from one+ /// to the other would name rows of the other one, as like as not its+ /// oldest history. A pane that cannot read both at once reads them one+ /// after the other.+ fn get_screen_lines(&self, lines: Range<StableRowIndex>) -> (StableRowIndex, Vec<Line>) {+ let lines = on_screen(&self.get_dimensions(), lines);+ // Not asked: a screen can answer an empty range with a row.+ if lines.is_empty() {+ return (lines.start, vec![]);+ }+ self.get_lines(lines)+ }+fn with_lines_mut(&self, lines: Range<StableRowIndex>, with_lines: &mut dyn WithPaneLines);fn for_each_logical_line_in_stable_range_mut(@@ -805,6 +820,16 @@ pub fn impl_get_logical_lines_via_get_lines<P: Pane + ?Sized>(lines}+/// The rows of `lines` on the screen `dims` describe.+pub fn on_screen(+ dims: &RenderableDimensions,+ lines: Range<StableRowIndex>,+) -> Range<StableRowIndex> {+ let top = dims.physical_top;+ let start = lines.start.max(top);+ start..lines.end.min(top + dims.viewport_rows as StableRowIndex).max(start)+}+/// A helper that allows you to implement Pane::get_lines in terms/// of your Pane::with_lines_mut method.pub fn impl_get_lines_via_with_lines<P: Pane + ?Sized>(@@ -986,6 +1011,28 @@ mod test {.collect::<Vec<_>>()}+ // A range that ends before it starts is one of those asked about.+ #[allow(clippy::reversed_empty_ranges)]+ #[test]+ fn only_rows_on_the_screen_are_on_it() {+ let dims = RenderableDimensions {+ viewport_rows: 24,+ physical_top: 100,+ ..RenderableDimensions::default()+ };+ assert_eq!(on_screen(&dims, 90..110), 100..110);+ assert_eq!(on_screen(&dims, 120..200), 120..124);+ assert!(on_screen(&dims, 0..100).is_empty());+ assert!(on_screen(&dims, 124..130).is_empty());+ assert!(on_screen(&dims, 110..105).is_empty());+ // The alternate screen numbers its rows from nought.+ let alt = RenderableDimensions {+ viewport_rows: 24,+ ..RenderableDimensions::default()+ };+ assert_eq!(on_screen(&alt, 0..5000), 0..24);+ }+#[test]fn logical_lines() {let text = "Hello there this is a long line.\nlogical line two\nanother long line here\nlogical line four\nlogical line five\ncap it off with another long line";diff --git a/mux/src/renderable.rs b/mux/src/renderable.rsindex af0ab65b..e346ac4d 100644--- a/mux/src/renderable.rs+++ b/mux/src/renderable.rs@@ -86,6 +86,20 @@ pub fn terminal_get_lines((first, lines)}+/// Implements Pane::get_screen_lines for Terminal: the screen's bounds and+/// its rows, read in the one hold the caller has of it.+pub fn terminal_get_screen_lines(+ term: &mut Terminal,+ lines: Range<StableRowIndex>,+) -> (StableRowIndex, Vec<Line>) {+ let lines = crate::pane::on_screen(&terminal_get_dimensions(term), lines);+ // Not asked: a screen can answer an empty range with a row.+ if lines.is_empty() {+ return (lines.start, vec![]);+ }+ terminal_get_lines(term, lines)+}+/// Implements Pane::get_dimensions for Terminalpub fn terminal_get_dimensions(term: &mut Terminal) -> RenderableDimensions {let size = term.get_size();