new: pane:get_lines_as_escapes()

refs: https://github.com/wez/wezterm/issues/4780
This commit is contained in:
Wez Furlong committed 2024-01-27 11:22:48 -07:00
1 parent b2ae5ade79
commit f30ea0a6eb
7 files changed
+147 -13

No files matched your search

+1
View File
@@ -17,5 +17,6 @@ parking_lot = "0.12"
portable-pty = { path = "../../pty" }
smol = "1.2"
termwiz = { path = "../../termwiz" }
termwiz-funcs = { path = "../termwiz-funcs" }
mux = { path = "../../mux" }
url-funcs = { path = "../url-funcs" }
+13
View File
@@ -4,6 +4,7 @@ use mlua::Value;
use std::cmp::Ordering;
use std::sync::Arc;
use termwiz::cell::SemanticType;
use termwiz_funcs::lines_to_escapes;
use url_funcs::Url;
use wezterm_term::{SemanticZone, StableRowIndex};
@@ -225,6 +226,18 @@ impl UserData for MuxPane {
Ok(text)
});
methods.add_method("get_lines_as_escapes", |_, this, nlines: Option<usize>| {
let mux = get_mux()?;
let pane = this.resolve(&mux)?;
let dims = pane.get_dimensions();
let nlines = nlines.unwrap_or(dims.viewport_rows);
let bottom_row = dims.physical_top + dims.viewport_rows as isize;
let top_row = bottom_row.saturating_sub(nlines as isize);
let (_first_row, lines) = pane.get_lines(top_row..bottom_row);
let text = lines_to_escapes(lines).map_err(mlua::Error::external)?;
Ok(text)
});
methods.add_method(
"get_logical_lines_as_text",
|_, this, nlines: Option<usize>| {