aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/panes/unit
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2026-03-14 08:35:00 +0100
committerGitHub <noreply@github.com>2026-03-14 08:35:00 +0100
commita1e224754759252778d8d3c30050e10bc9a82f84 (patch)
tree326ed657bbbb34ed98006f6bbc36fd918fdb1b0a /zellij-server/src/panes/unit
parentAdd `--pane-id` and `--tab-id` to all relevant CLI commands (#4846) (diff)
downloadsl0ppij-a1e224754759252778d8d3c30050e10bc9a82f84.tar.gz
sl0ppij-a1e224754759252778d8d3c30050e10bc9a82f84.tar.xz
sl0ppij-a1e224754759252778d8d3c30050e10bc9a82f84.zip
Ansi dump support (#4848)
* add missing pane-id and tab-id arguments to all cli actions * rustfmt * dump-screen --ansi * edit-scrollback --ansi * add --ansi to subscribe * add tests for ansi additions * add ansi render report to plugins * rustfmt * fix e2e tests * add pr
Diffstat (limited to 'zellij-server/src/panes/unit')
-rw-r--r--zellij-server/src/panes/unit/grid_tests.rs122
1 files changed, 122 insertions, 0 deletions
diff --git a/zellij-server/src/panes/unit/grid_tests.rs b/zellij-server/src/panes/unit/grid_tests.rs
index c482d802..17c74006 100644
--- a/zellij-server/src/panes/unit/grid_tests.rs
+++ b/zellij-server/src/panes/unit/grid_tests.rs
@@ -5026,6 +5026,128 @@ fn pane_contents_no_scrollback_when_flag_false() {
}
// =====================================================================
+// pane_contents_with_ansi Tests
+// =====================================================================
+
+fn create_grid_with_colored_scrollback() -> Grid {
+ let sixel_image_store = Rc::new(RefCell::new(SixelImageStore::default()));
+ let terminal_emulator_color_codes = Rc::new(RefCell::new(HashMap::new()));
+ let mut grid = Grid::new(
+ 5,
+ 40,
+ Rc::new(RefCell::new(Palette::default())),
+ terminal_emulator_color_codes,
+ Rc::new(RefCell::new(LinkHandler::new())),
+ Rc::new(RefCell::new(None)),
+ sixel_image_store,
+ Style::default(),
+ false,
+ true,
+ true,
+ true,
+ false,
+ );
+ let mut parser = vte::Parser::new();
+ for i in 0..25 {
+ let line = format!("\x1b[31mred line {}\x1b[0m\r\n", i);
+ for byte in line.as_bytes() {
+ parser.advance(&mut grid, *byte);
+ }
+ }
+ grid
+}
+
+#[test]
+fn pane_contents_with_ansi_preserves_escape_codes() {
+ let grid = create_grid_with_colored_scrollback();
+ let result = grid.pane_contents_with_ansi(false, None);
+ let has_ansi = result.viewport.iter().any(|line| line.contains("\x1b["));
+ assert!(
+ has_ansi,
+ "pane_contents_with_ansi should preserve ANSI escape codes in viewport. Lines: {:?}",
+ result.viewport
+ );
+}
+
+#[test]
+fn pane_contents_strips_escape_codes() {
+ let grid = create_grid_with_colored_scrollback();
+ let result = grid.pane_contents(false, None);
+ let has_ansi = result.viewport.iter().any(|line| line.contains("\x1b["));
+ assert!(
+ !has_ansi,
+ "pane_contents should strip ANSI escape codes from viewport. Lines: {:?}",
+ result.viewport
+ );
+}
+
+#[test]
+fn pane_contents_with_ansi_scrollback_preserves_escape_codes() {
+ let grid = create_grid_with_colored_scrollback();
+ let result = grid.pane_contents_with_ansi(true, None);
+ let has_ansi = result
+ .lines_above_viewport
+ .iter()
+ .any(|line| line.contains("\x1b["));
+ assert!(
+ has_ansi,
+ "pane_contents_with_ansi should preserve ANSI escape codes in scrollback. Lines: {:?}",
+ result.lines_above_viewport
+ );
+}
+
+#[test]
+fn pane_contents_with_ansi_scrollback_truncation() {
+ let grid = create_grid_with_colored_scrollback();
+ let result = grid.pane_contents_with_ansi(true, Some(3));
+ assert_eq!(
+ result.lines_above_viewport.len(),
+ 3,
+ "Should truncate to 3 scrollback lines"
+ );
+ let all_have_ansi = result
+ .lines_above_viewport
+ .iter()
+ .all(|line| line.contains("\x1b["));
+ assert!(
+ all_have_ansi,
+ "All truncated scrollback lines should contain ANSI codes. Lines: {:?}",
+ result.lines_above_viewport
+ );
+}
+
+#[test]
+fn pane_contents_with_ansi_no_scrollback_when_flag_false() {
+ let grid = create_grid_with_colored_scrollback();
+ let result = grid.pane_contents_with_ansi(false, Some(5));
+ assert!(
+ result.lines_above_viewport.is_empty(),
+ "get_full_scrollback=false should never collect scrollback even with ansi"
+ );
+}
+
+#[test]
+fn pane_contents_with_ansi_and_without_have_same_text() {
+ let grid = create_grid_with_colored_scrollback();
+ let plain = grid.pane_contents(false, None);
+ let ansi = grid.pane_contents_with_ansi(false, None);
+ assert_eq!(
+ plain.viewport.len(),
+ ansi.viewport.len(),
+ "Both should have the same number of viewport lines"
+ );
+ // Strip ANSI codes from the ansi version and compare plain text content
+ let ansi_escape = regex::Regex::new(r"\x1b\[[0-9;]*m").unwrap();
+ for (plain_line, ansi_line) in plain.viewport.iter().zip(ansi.viewport.iter()) {
+ let stripped = ansi_escape.replace_all(ansi_line, "").to_string();
+ assert_eq!(
+ *plain_line, stripped,
+ "After stripping ANSI codes, text content should match"
+ );
+ }
+}
+
+// =====================================================================
// Highlight Layer Priority Tests
// =====================================================================