libtmux Reference MCP Search
On this page

pane.observe.Pane.capture_lines

View as Markdown

Module
pane.observe
Declared in
Pane
Package
libtmux
Source
crates/libtmux/src/pane/observe.rs
capture_lines ( self , options : CaptureOptions ) Result<Vec<CapturedLine>, Error>
method [source]
method [source]
capture_lines

Capture with the per-line flags tmux records, marking shell prompts.

tmux records where a prompt and its output begin from the OSC 133 sequences a shell emits, and keeps those marks as lines scroll into history. That is what answers "show me the last command's output" exactly, rather than by guessing at a prompt's shape.

Every CapturedLine::starts_prompt is false when the pane's shell does not emit OSC 133, which is the common case: fish does, bash and zsh do not without shell integration installed. An empty result is a real answer about the shell, not a failure.

Errors

Returns Error::UnsupportedCapability below tmux 3.7, which is where capture-pane -F arrived, and an error when tmux refuses the capture.

Examples

use libtmux::CaptureOptions;

let guard = libtmux::test::TestServer::new().await?;
let server = guard.server();
let session = server.new_session("prompts").await?;
let pane = session.panes().await?.remove(0);

if server.capabilities().await?.tmux_version().meets(&libtmux::since::CAPTURE_LINE_FLAGS) {
    let lines = pane.capture_lines(CaptureOptions::history()).await?;
    // Without shell integration nothing is marked, which is an answer.
    let prompts = lines.iter().filter(|line| line.starts_prompt).count();
    assert!(prompts <= lines.len());
}

guard.shutdown().await?;

0 declared, 0 inherited

Esc

Type to search.