Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux latest

Pane.capture_pane

Capture text from pane.

Source and package
Qualified name
libtmux.Pane.capture_pane
Module
libtmux
Declared in
Pane
Package
libtmux
Source
src/libtmux/pane.py
Other languages
Perlmethod Erlang PowerShell Julia Elixir Haskell Common Lisp RubyLuaTypeScriptRustGoJavaC#C++SwiftKotlinScalaOCamlF#Clojure
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

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
$
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

  • 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.

tmux command#

The tmux commands behind capture_pane.

tmux C API#

The C declarations in tmux that implement these commands.

Guides#

Pages that discuss capture_pane.

In other ports#

Read a pane’s visible contents

Equivalents of Read a pane’s visible contents in other languages
Language Equivalent
Ruby LibTmux::Pane#capture
Lua libtmux.Pane:capture
Erlang tmux_pane:capture/2
Haskell No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.
TypeScript pane.Pane.capture
Rust pane.Pane.capture
Go tmux.Pane.Capture
Java io.github.libtmux.Pane.capture
Clojure libtmux.core/capture!
Kotlin io.github.libtmux.kotlin.Pane.capture
Scala io.github.libtmux.scaladsl.Pane.capture
C# LibTmux.Pane.CaptureAsync
F# LibTmux.FSharp.Pane.capture
C++ libtmux::Pane::capture
Swift Server.capture(_:includingHistory:)
OCaml Libtmux_unix.Client.capture_text
Perl LibTmux::Server::capture_pane Explicit Server operation. Captured entities remain local observations; use a new snapshot to observe changes.

No equivalent is recorded in PowerShell, Julia, Elixir or Common Lisp.

Esc

Type to search.

Reference previewOpen reference