# LibTmux.capture_bytes

- **Module:** LibTmux
- **Package:** LibTmux
- **Language:** Julia
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/pane_io.jl#L48
- **Page:** https://libtmux.org/en/julia/latest/reference/libtmux-capture_bytes/

```
capture_bytes(
    connection::LibTmux.ControlConnection,
    pane::LibTmux.PaneRef;
    start_line,
    end_line,
    join_wrapped,
    preserve_trailing,
    escapes,
    alternate,
    max_bytes,
    timeout,
    cancel
)

capture_bytes(
    server::LibTmux.Server,
    pane::LibTmux.PaneRef;
    start_line,
    end_line,
    join_wrapped,
    preserve_trailing,
    escapes,
    alternate,
    max_bytes,
    kwargs...
)
```

## Methods

### `capture_bytes` (overload 1)

```julia
capture_bytes(
    connection::LibTmux.ControlConnection,
    pane::LibTmux.PaneRef;
    start_line,
    end_line,
    join_wrapped,
    preserve_trailing,
    escapes,
    alternate,
    max_bytes,
    timeout,
    cancel
)
```

[Source](https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/control_io.jl#L84).

Capture through the existing control connection using a uniquely owned tmux buffer and private local spool. Pane text never enters the control reply parser. The buffer size is checked before disk output, and the same-queue fence proves `save-buffer` completion before reading. This transport requires the tmux daemon and Julia to share the local filesystem. tmux's file write may block its event loop; yielding Julia I/O does not make that write asynchronous.

```julia
capture_bytes(connection::ControlConnection, pane::PaneRef; kwargs...)
```



Screen options match `capture_bytes(server, pane)`. `timeout` is one operation deadline. Cancellation is followed by a separate uncancelled 900 ms buffer cleanup budget. If remote cleanup cannot be proved, `ControlBufferCleanupError` retains its buffer reference; a primary failure is preserved in a `CompositeException`. The owned local spool is always removed. There is no subprocess fallback or retry.

### `capture_bytes` (overload 2)

```julia
capture_bytes(
    server::LibTmux.Server,
    pane::LibTmux.PaneRef;
    start_line,
    end_line,
    join_wrapped,
    preserve_trailing,
    escapes,
    alternate,
    max_bytes,
    kwargs...
)
```

[Source](https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/pane_io.jl#L64).

Capture tmux's screen representation as owned bytes. The default keeps screen line breaks and tmux's usual trailing-space trimming. `join_wrapped=true` joins soft-wrapped lines and implies tmux's trailing-space preservation. `preserve_trailing=true` requests `capture-pane -N`; `escapes=true` includes style escape sequences. No additional trimming or newline conversion occurs.

```julia
capture_bytes(server, pane; start_line=nothing, end_line=nothing,
              join_wrapped=false, preserve_trailing=false, escapes=false,
              alternate=false, max_bytes=8388608, kwargs...)
```



Negative line numbers address history; `start_line=:history` selects its beginning and `end_line=:bottom` selects the screen bottom. `alternate=true` requests the alternate screen and errors if it is unavailable. Screen capture does not reconstruct the original terminal byte stream.

## Parameters

- `connection` (`LibTmux.ControlConnection`) (for `capture_bytes(connection, pane, start_line, end_line, join_wrapped, preserve_trailing, escapes, alternate, max_bytes, timeout, cancel)`)
- `pane` (`LibTmux.PaneRef`)
- `start_line`
  Default: `nothing`.
- `end_line`
  Default: `nothing`.
- `join_wrapped` (`Bool`)
  Default: `false`.
- `preserve_trailing` (`Bool`)
  Default: `false`.
- `escapes` (`Bool`)
  Default: `false`.
- `alternate` (`Bool`)
  Default: `false`.
- `max_bytes` (`Int`)
  Default: `8 * 1024 ^ 2`.
- `timeout` (`Real`) (for `capture_bytes(connection, pane, start_line, end_line, join_wrapped, preserve_trailing, escapes, alternate, max_bytes, timeout, cancel)`)
  Default: `5.0`.
- `cancel` (`Union{Nothing, CancellationToken}`) (for `capture_bytes(connection, pane, start_line, end_line, join_wrapped, preserve_trailing, escapes, alternate, max_bytes, timeout, cancel)`)
  Default: `nothing`.
- `server` (`LibTmux.Server`) (for `capture_bytes(server, pane, start_line, end_line, join_wrapped, preserve_trailing, escapes, alternate, max_bytes, kwargs)`)
- `kwargs` (for `capture_bytes(server, pane, start_line, end_line, join_wrapped, preserve_trailing, escapes, alternate, max_bytes, kwargs)`)
