# pane.Pane.wait_for_text

- **Module:** pane.Pane
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/f0e37052c232636b61d095817046e6bfc8f2ca40/crates/libtmux/src/pane/observe.rs#L309
- **Page:** https://libtmux.org/en/rs/latest/reference/pane-pane-wait_for_text/

```
pane.Pane.wait_for_text(self, needle: impl AsRef<[u8]>, within: Duration) -> Result<PaneWait, Error>
```

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.

## Example

```rust
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);
```
