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-rs latest

Pane.capture_lines

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

Source and package
Qualified name
libtmux::pane::Pane::capture_lines
Module
pane
Declared in
Pane
Package
libtmux
Source
crates/libtmux/src/pane/observe.rs
pub async fn capture_lines( &self, options: CaptureOptions ) -> Result<Vec<CapturedLine>, Error>

Description#

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().has_behavior(&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?;
Parameters

tmux command#

The tmux commands behind capture_lines.

tmux C API#

The C declarations in tmux that implement these commands.

Esc

Type to search.

Reference previewOpen reference