Skip to content

Commit 240c88e

Browse files
committed
Pane(feat[capture_pane]): add alternate-screen, quiet, and escape-markup flags
why: capture-pane supports flags for alternate screen capture, silent error handling, and markup escaping that were not exposed. what: - Add alternate_screen (-a), quiet (-q), escape_markup (-M, 3.6+) parameters - Version-gate escape_markup with has_gte_version("3.6") - Add tests for quiet, alternate_screen, and escape_markup flags
1 parent 680ac34 commit 240c88e

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/libtmux/pane.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ def capture_pane(
326326
join_wrapped: bool = False,
327327
preserve_trailing: bool = False,
328328
trim_trailing: bool = False,
329+
alternate_screen: bool = False,
330+
quiet: bool = False,
331+
escape_markup: bool = False,
329332
) -> list[str]:
330333
r"""Capture text from pane.
331334
@@ -371,6 +374,17 @@ def capture_pane(
371374
Requires tmux 3.4+. If used with tmux < 3.4, a warning
372375
is issued and the flag is ignored.
373376
Default: False
377+
alternate_screen : bool, optional
378+
Capture from the alternate screen (``-a`` flag).
379+
Default: False
380+
quiet : bool, optional
381+
Suppress errors silently (``-q`` flag).
382+
Default: False
383+
escape_markup : bool, optional
384+
Escape markup in the output (``-M`` flag). Requires tmux 3.6+.
385+
Default: False
386+
387+
.. versionadded:: 0.45
374388
375389
Returns
376390
-------
@@ -418,6 +432,18 @@ def capture_pane(
418432
"trim_trailing requires tmux 3.4+, ignoring",
419433
stacklevel=2,
420434
)
435+
if alternate_screen:
436+
cmd.append("-a")
437+
if quiet:
438+
cmd.append("-q")
439+
if escape_markup:
440+
if has_gte_version("3.6", tmux_bin=self.server.tmux_bin):
441+
cmd.append("-M")
442+
else:
443+
warnings.warn(
444+
"escape_markup requires tmux 3.6+, ignoring",
445+
stacklevel=2,
446+
)
421447
return self.cmd(*cmd).stdout
422448

423449
def send_keys(

tests/test_pane_capture_pane.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,37 @@ def prompt_ready() -> bool:
470470
# Check warning was issued
471471
assert len(w) == 1
472472
assert "trim_trailing requires tmux 3.4+" in str(w[0].message)
473+
474+
475+
def test_capture_pane_quiet(session: Session) -> None:
476+
"""Test capture_pane with quiet flag suppresses errors."""
477+
pane = session.active_window.active_pane
478+
assert pane is not None
479+
480+
# Quiet mode should not raise, even in edge cases
481+
result = pane.capture_pane(quiet=True)
482+
assert isinstance(result, list)
483+
484+
485+
def test_capture_pane_alternate_screen(session: Session) -> None:
486+
"""Test capture_pane with alternate_screen flag."""
487+
pane = session.active_window.active_pane
488+
assert pane is not None
489+
490+
# Capture from alternate screen — may be empty, but should not error
491+
result = pane.capture_pane(alternate_screen=True)
492+
assert isinstance(result, list)
493+
494+
495+
def test_capture_pane_escape_markup(session: Session) -> None:
496+
"""Test capture_pane with escape_markup flag (3.6+)."""
497+
from libtmux.common import has_gte_version
498+
499+
if not has_gte_version("3.6"):
500+
pytest.skip("Requires tmux 3.6+")
501+
502+
pane = session.active_window.active_pane
503+
assert pane is not None
504+
505+
result = pane.capture_pane(escape_markup=True)
506+
assert isinstance(result, list)

0 commit comments

Comments
 (0)