# Server.waitForOutput(in:matching:stoppingAt:requiringFreshOutput:timeout:tailLimit:)

- **Module:** Server
- **Package:** libtmux-swift
- **Language:** Swift
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-swift/blob/f02a4668570e1cc5198c941413750e021f42c214/Sources/LibTmux/WaitForOutput.swift#L114
- **Page:** https://libtmux.org/reference/swift/server-waitforoutput(in-matching-stoppingat-requiringfreshoutput-timeout-taillimit-)/

```
Server.waitForOutput(in:matching:stoppingAt:requiringFreshOutput:timeout:tailLimit:)(in: Pane, matching: [RegexPattern], stoppingAt: [RegexPattern], requiringFreshOutput: Bool, timeout: Duration, tailLimit: Int) -> OutputWait
```

Waits until a pane prints something, driven by tmux output events.

tmux has no hook that fires on pane output, so a wait that only has
commands to work with must re-read the pane on a timer. A control
connection is told instead: `%output` arrives as the pane writes.

What arrives there is raw terminal bytes — keystroke echo, escape
sequences, a word split across two notifications — so it is used as a
doorbell rather than as text. Each burst wakes one capture, and the
matching runs against the rendered grid, which is the same text a
person reads. That keeps the accuracy of a capture and pays for it only
when something actually happened. A small liveness probe runs while the
pane is quiet so removing it ends the wait instead of looking like a
timeout.

The conditions are checked before they are blocked on. A match or stop
already on screen returns at once, with ``OutputWait/matchedAtEntry``
set. Pass `requiringFreshOutput` when only a new occurrence counts.

- Parameters:
  - pane: the pane to watch.
  - patterns: bounded regular expressions, any of which ends the wait. Empty
    means any new output at all does — the right choice when what the
    pane prints is not known in advance.
  - stops: bounded regular expressions that end the wait as
    ``OutputWait/Outcome/stopped``. A failure marker belongs here: a
    build that fails at five seconds should not hold the wait open for
    the rest of the timeout.
  - requireFresh: only count output that arrives after this call, so a
    match already on screen is waited past rather than returned.
  - timeout: how long to wait before giving up.
  - tailLimit: how many trailing lines to report back.

## Raises

- `OutputWaitError`
