# pane.Pane.waitForText

- **Module:** pane
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-ts/blob/073b9d7dedad900bff6f5ec0ea47794e40225870/packages/libtmux/src/pane.ts#L431
- **Page:** https://libtmux.org/en/ts/latest/reference/pane-pane-waitfortext/

```
waitForText(
  pattern: string | RegExp,
  options?: ProgramWaitOptions,
): Promise<string>
```

Resolve with the first line of this pane's screen that `pattern` matches: a substring, or a regular expression tested against each line. A line the pane's width wrapped is one line here, matched and returned whole, so the result can be wider than the pane.

The screen is read at once, then again each time tmux reports that the
pane printed, at most every 50 ms, and once a second besides. Use it to
wait for a prompt, or for a full-screen program's first screen before
typing into it. Giving up leaves the pane as it was: a timeout throws
[`WaitTimeoutError`](/en/ts/latest/reference/errors-waittimeouterror/) and an abort throws [`TmuxTransportError`](/en/ts/latest/reference/errors-tmuxtransporterror/)
of kind `cancelled`. A pane whose program has exited without the text
rejects with [`LibTmuxError`](/en/ts/latest/reference/errors-libtmuxerror/), and a pane that is gone, or goes during
the wait, with [`ObjectNotFoundError`](/en/ts/latest/reference/errors-objectnotfounderror/).

Requires tmux 3.8 or newer.

## Examples

```ts
await using top = await server.spawn(["sh", "-c", "echo ready; exec cat"]);
await top.pane.waitForText("ready", { timeoutMs: 10_000 }); // "ready"
```

## Parameters

- `pattern` (`string | RegExp`)
- `options?` (`ProgramWaitOptions`)

## tmux command

The tmux commands behind `waitForText`.

- [`wait-for`](/en/tmux/latest/manual/wait-for/)
- [`capture-pane`](/en/tmux/latest/manual/capture-pane/)
- [`display-message`](/en/tmux/latest/manual/display-message/)

## tmux C API

The C declarations in tmux that implement these commands.

- [`cmd_wait_for_entry`](/en/tmux/latest/reference/c-variable-cmd_wait_for_entry/) (attribute)
- [`cmd_wait_for_exec`](/en/tmux/latest/reference/c-function-cmd-wait-for-c-cmd_wait_for_exec/) (function)
- [`cmd_capture_pane_entry`](/en/tmux/latest/reference/c-variable-cmd_capture_pane_entry/) (attribute)
- [`cmd_capture_pane_exec`](/en/tmux/latest/reference/c-function-cmd-capture-pane-c-cmd_capture_pane_exec/) (function)
- [`cmd_display_message_entry`](/en/tmux/latest/reference/c-variable-cmd_display_message_entry/) (attribute)
- [`cmd_display_message_exec`](/en/tmux/latest/reference/c-function-cmd-display-message-c-cmd_display_message_exec/) (function)
