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

PaneOutput.snapshot

Capture the pane's visible screen at an ordered point in this stream.

Source and package
Qualified name
libtmux::control::PaneOutput::snapshot
Module
control
Declared in
PaneOutput
Package
libtmux
Source
crates/libtmux/src/control.rs
pub async fn snapshot( &mut self, mut on_output: impl FnMut(&[u8]), ) -> Result<Vec<TmuxText>, Error>

Description#

on_output receives every unread chunk tmux ordered before the capture block. The callback owns any retention policy, so libtmux does not retain those chunks. It runs synchronously and should return promptly.

Each chunk passed to on_output is consumed from this stream and is not repeated by Self::next_chunk(), even when this returns an error.

The visible screen and preceding output may overlap: the screen is tmux's rendered grid, while the callback receives the raw terminal byte stream that reached that grid.

Errors

Returns an error when the connection closes, the command deadline elapses, or tmux refuses the capture, including when the pane vanished.

Cancel safety

Partly happened: chunks already passed to on_output stay consumed, so what the callback kept is the only copy. The stream stays usable.

Examples#

let mut output = pane.stream_output().await?;
let mut preceding = Vec::new();
let visible = output
.snapshot(|chunk| preceding.extend_from_slice(chunk))
.await?;
println!("{} visible lines after {} raw bytes", visible.len(), preceding.len());
output.shutdown().await
Parameters

tmux command#

The tmux commands behind snapshot.

tmux C API#

The C declarations in tmux that implement these commands.

Esc

Type to search.

Reference previewOpen reference