Skip to content

Commit 557681c

Browse files
committed
Pane(feat[capture_frame]): Forward capture_pane() flags
why: Allow users to control capture behavior when using capture_frame() for snapshot testing, such as capturing colored output or joining wrapped lines. what: - Add escape_sequences parameter for ANSI escape sequences - Add escape_non_printable parameter for octal escapes - Add join_wrapped parameter for joining wrapped lines - Add preserve_trailing parameter for trailing spaces - Add trim_trailing parameter with tmux 3.4+ version check - Forward all flags to capture_pane() call
1 parent 4530e8f commit 557681c

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/libtmux/pane.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,13 @@ def capture_frame(
430430
content_width: int | None = None,
431431
content_height: int | None = None,
432432
overflow_behavior: OverflowBehavior = "truncate",
433+
escape_sequences: bool = False,
434+
escape_non_printable: bool = False,
435+
join_wrapped: bool = False,
436+
preserve_trailing: bool = False,
437+
trim_trailing: bool = False,
433438
) -> TextFrame:
434-
"""Capture pane content as a TextFrame.
439+
r"""Capture pane content as a TextFrame.
435440
436441
Combines :meth:`capture_pane` with :class:`~libtmux.textframe.TextFrame`
437442
for visualization and snapshot testing.
@@ -460,6 +465,19 @@ def capture_frame(
460465
How to handle content that exceeds frame dimensions.
461466
Defaults to ``"truncate"`` since pane content may exceed
462467
nominal dimensions during terminal transitions.
468+
escape_sequences : bool, optional
469+
Include ANSI escape sequences for text and background attributes.
470+
Useful for capturing colored output. Default: False
471+
escape_non_printable : bool, optional
472+
Escape non-printable characters as octal ``\\xxx`` format.
473+
Default: False
474+
join_wrapped : bool, optional
475+
Join wrapped lines back together. Default: False
476+
preserve_trailing : bool, optional
477+
Preserve trailing spaces at each line's end. Default: False
478+
trim_trailing : bool, optional
479+
Trim trailing positions with no characters.
480+
Requires tmux 3.4+. Default: False
463481
464482
Returns
465483
-------
@@ -486,8 +504,16 @@ def capture_frame(
486504
"""
487505
from libtmux.textframe import TextFrame as TextFrameClass
488506

489-
# Capture content
490-
lines = self.capture_pane(start=start, end=end)
507+
# Capture content with all flags forwarded
508+
lines = self.capture_pane(
509+
start=start,
510+
end=end,
511+
escape_sequences=escape_sequences,
512+
escape_non_printable=escape_non_printable,
513+
join_wrapped=join_wrapped,
514+
preserve_trailing=preserve_trailing,
515+
trim_trailing=trim_trailing,
516+
)
491517

492518
# Use pane dimensions if not specified
493519
self.refresh()

0 commit comments

Comments
 (0)