# tmux.Pane.WaitForText

- **Module:** tmux
- **Package:** github.com/libtmux/libtmux-go/tmux
- **Language:** Go
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-go/blob/2506df7dc1efe4293452a1c78b01a2bffa33a6a0/tmux/pane_text_wait.go#L147
- **Page:** https://libtmux.org/en/go/latest/reference/tmux-pane-waitfortext/

```
func (p Pane) WaitForText(
	ctx context.Context,
	req WaitForTextRequest,
) (PaneTextWait, error)
```

WaitForText polls the receiver's visible screen until it holds req.Text, the pane or server ends, or ctx ends. It polls on every supported tmux release and never opens a control client; [PaneObservation.WaitFor] is the push-based wait for tmux 3.7 and newer.

The wait is level-triggered. Text already on screen matches at once, with
[PaneTextWait.MatchedAtEntry] set, and so does a shell's echo of a typed
command that contains req.Text. Match on what the command prints, not on
the command: printf 'NEE%s' DLE never puts NEEDLE in the typed line.
[PaneObservation.WaitFor] differs by reporting only output after its
baseline. A caller who needs only new output on tmux 3.3a through 3.6
checks the screen before typing and picks text the screen lacks.

Only the visible screen is read, never history, so text that has scrolled
off is not seen. Wrapped rows are joined, so text may straddle the wrap
column. A poll sees the final state of text a program overwrote with a
carriage return, and text printed before a full-screen program started is
not on the screen being read.

Every read is one ordinary tmux process, so a server bound to a
[Connection] is refused with [ErrConnectionRequiresProcess].
Each read runs the owner's after-capture-pane hook, and a hook that prints
adds its output to the text.
The read asks for liveness through [run-shell](/en/tmux/latest/manual/run-shell/), which fires no hook.

The text is matched before the pane's liveness is acted on, so a complete
read of a pane that has since died still matches. A pane or server that
ends first returns a [*PaneEndedError]. A deadline or cancel returns
ctx.Err, with the text of the last complete read. An empty req.Text or a
negative interval fails before any tmux command runs with
[ErrInvalidWaitForText].

## Parameters

- `ctx` (`context.Context`)
- `req` (`WaitForTextRequest`)
