Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Python API

Python documentation

View as Markdown

Module
libtmux
Declared in
Pane
Package
libtmux
Source
src/libtmux/pane.py
Other languages
RubyLuaTypeScriptRustGoJava.NETC++Swift
capture_pane
( 16 parameters ) ( self , start : t.Literal["-"] | int | None = ... , end : t.Literal["-"] | int | None = ... , escape_sequences : bool = ... , escape_non_printable : bool = ... , join_wrapped : bool = ... , preserve_trailing : bool = ... , trim_trailing : bool = ... , alternate_screen : bool = ... , quiet : bool = ... , mode_screen : bool = ... , pending : bool = ... , hyperlinks : bool = ... , line_numbers : bool = ... , line_flags : bool = ... , to_buffer : str )
→ None
( 16 parameters ) ( self , start : t.Literal["-"] | int | None = ... , end : t.Literal["-"] | int | None = ... , escape_sequences : bool = ... , escape_non_printable : bool = ... , join_wrapped : bool = ... , preserve_trailing : bool = ... , trim_trailing : bool = ... , alternate_screen : bool = ... , quiet : bool = ... , mode_screen : bool = ... , pending : bool = ... , hyperlinks : bool = ... , line_numbers : bool = ... , line_flags : bool = ... , to_buffer : None = ... )
→ list[str]
( 16 parameters ) ( self , start : t.Literal["-"] | int | None = None , end : t.Literal["-"] | int | None = None , escape_sequences : bool = False , escape_non_printable : bool = False , join_wrapped : bool = False , preserve_trailing : bool = False , trim_trailing : bool = False , alternate_screen : bool = False , quiet : bool = False , mode_screen : bool = False , pending : bool = False , hyperlinks : bool = False , line_numbers : bool = False , line_flags : bool = False , to_buffer : str | None = None )
→ list[str] | None
method3 overloads [source]
method3 overloads [source]
capture_pane

Capture text from pane.

$ tmux capture-pane to pane. $ tmux capture-pane -S -10 to pane. $ tmux capture-pane -E 3 to pane. $ tmux capture-pane -S - -E - to pane.

Parameters
  • start ( t.Literal["-"] | int | None ) – Specify the starting line number. Zero is the first line of the visible pane. Positive numbers are lines in the visible pane. Negative numbers are lines in the history. - is the start of the history. Default: None

  • end ( t.Literal["-"] | int | None ) – Specify the ending line number. Zero is the first line of the visible pane. Positive numbers are lines in the visible pane. Negative numbers are lines in the history. - is the end of the visible pane. Default: None

  • escape_sequences ( bool ) – Include ANSI escape sequences for text and background attributes (-e flag). Useful for capturing colored output. Default: False

  • escape_non_printable ( bool ) – Escape non-printable characters as octal \\xxx format (-C flag). Useful for binary-safe capture. Default: False

  • join_wrapped ( bool ) – Join wrapped lines and preserve trailing spaces (-J flag). Lines that were wrapped by tmux will be joined back together. Default: False

  • preserve_trailing ( bool ) – Preserve trailing spaces at each line's end (-N flag). Default: False

  • trim_trailing ( bool ) – Trim trailing positions with no characters (-T flag). Only includes characters up to the last used cell. Requires tmux 3.4+. If used with tmux < 3.4, a warning is issued and the flag is ignored. Default: False

  • alternate_screen ( bool ) – Capture from the alternate screen (-a flag). Default: False added 0.56

  • quiet ( bool ) – Suppress errors silently (-q flag). Default: False added 0.56

  • mode_screen ( bool ) – Capture from the mode screen (e.g. copy mode) instead of the pane (-M flag). Requires tmux 3.6+. Default: False added 0.56

  • pending ( bool ) – Capture *pending output* — the bytes tmux has read from the pane but not yet committed to the terminal (-P flag). These are bytes that begin an incomplete escape sequence and are still pending the parser's ground state (tmux's input_pending() / since_ground buffer), distinct from the default capture (the pane's screen history). Useful for diagnosing programs whose output stalls mid-sequence. Default: False added 0.57

  • hyperlinks ( bool ) – Capture only hyperlink targets in the selected lines (-H flag). Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored. Default: False

  • line_numbers ( bool ) – Prefix each captured line with its line number (-L flag). Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored. Default: False

  • line_flags ( bool ) – Prefix each captured line with its flags, e.g. H for a line with a hyperlink (-F flag). Requires tmux 3.7+. If used with tmux < 3.7, a warning is issued and the flag is ignored. Default: False

  • to_buffer ( str | None ) – Write the capture into the named tmux buffer (-b flag) instead of returning it. When set, -p is omitted and the wrapper returns None. added 0.56

Returns

list[str] or None Captured pane content, or None when *to_buffer* is set.

Discussed in Capture pane output

In other ports Read a pane’s visible contents

Examples

>>> pane = window.split(shell='sh')
>>> pane.capture_pane()
['$']
>>> pane.send_keys('echo "Hello world"', enter=True)
>>> pane.capture_pane()
['$ echo "Hello world"', 'Hello world', '$']
>>> print(chr(10).join(pane.capture_pane()))
$ echo "Hello world"
Hello world
$
const lines = await pane.capture();
lines.at(-1);

0 declared, 0 inherited

Esc

Type to search.