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

pane.Pane.wait_for_text

Rust
  • Python Unavailable
  • Ruby Unavailable
  • Lua Unavailable
  • TypeScript Unavailable
  • Rust
  • Go Unavailable
  • Java Unavailable
  • .NET Unavailable
  • C++ Unavailable
  • Swift Unavailable

View as Markdown

Module
pane
Declared in
Pane
Package
libtmux
Source
crates/libtmux/src/pane/observe.rs
wait_for_text ( self , needle : impl AsRef<[u8]> , within : Duration ) → Result<PaneWait, Error>
method [source]
method [source]
wait_for_text

Wait until this pane's output contains needle.

Pane::wait_until takes a predicate over the lines instead.

Polls rather than streams, so it needs no feature: a caller who dispatches a command needs to know when it finished, and Pane::send_keys without that is half an operation. A control-mode subscription would answer sooner and is not available in a default build.

A look costs one capture-pane and looks are 120ms apart, which keeps a wait under ten dispatches a second and answers within an interval of the text appearing. The first look comes before the first sleep, so text already there when the wait begins is answered at once, and a within shorter than one interval buys exactly one look.

Each look reads the scrollback rather than the visible screen, and joins lines tmux wrapped. Both matter for correctness rather than completeness: text that scrolled off before the look would otherwise be missed and reported as absent, and a line wider than the pane arrives split, so a needle spanning the wrap point would never match.

A pane whose process ends answers PaneWait::Dead rather than running to the deadline, because waiting longer cannot change it.

A Pane::capture called immediately after this returns can occasionally miss the very output that satisfied the wait: tmux's own redraw of the screen a fast, multi-byte-heavy write produced can still be in flight when the next capture-pane reads it, independent of this crate. Raw tmux shows the same gap running the equivalent send-keys/capture-pane sequence directly. A caller sensitive to this should retry the capture rather than trust it on the first look.

Errors

Returns an error when tmux cannot be reached or refuses a capture. Running out of time is PaneWait::TimedOut , not an error.

Cancel safety

Nothing happened. A look only reads, so output a dropped wait missed stays in the scrollback, up to history-limit, for the next wait.

Examples

use libtmux::PaneWait;
use std::time::Duration;
pane.send_line("printf 'ready\\n'").await?;
let seen = pane.wait_for_text("ready", Duration::from_secs(10)).await?;
assert_eq!(seen, PaneWait::Arrived);

Discussed in Capture pane output · Testing with libtmux

0 declared, 0 inherited

Esc

Type to search.