# `libvt.contrib.tmux.capture`

Use {func}`~libvt.contrib.tmux.capture.build_tmux_capture_command` to
capture the pane's written extent and trailing styles together on tmux 3.4
and later. For raw captures, use the same pane, line range and line flags
with `capture-pane -e -p -N -T` and `capture-pane -e -p -N`.

```python
>>> from libvt.contrib.tmux import decode_tmux_capture
>>> capture = decode_tmux_capture(
...     b"\n",
...     rows=1, cols=3, trim_trailing=True,
...     untrimmed_capture=b"\x1b[41m   \n",
... )
>>> capture.snapshot.lines
('',)
>>> capture.snapshot[0, 2].style.bg.name
'RED'
>>> capture.completeness.exact_cells
True
```

An older tmux can return the same trailing spaces for a written blank row
and an erased row. The decoder retains the available styles, and reports
`trailing_cells` in `completeness.unexposed_fields` when it cannot establish
which spaces were written. A `-T` capture without its untrimmed companion
likewise reports uncertainty when a row stops short of the pane width.

Preserve empty physical rows when passing a sequence of lines. A capture
with missing viewport, requested history, or requested saved-primary rows
reports `capture_rows` and clears `exact_cells` and `exact_wraps`. The
generation bracket reports the metadata comparison independently.

## Continue after a capture

{attr}`~libvt.contrib.tmux.capture.CaptureCompleteness.exact_cells`
describes the captured frame. Later input can depend on earlier bytes.
{attr}`~libvt.contrib.tmux.capture.CaptureCompleteness.unexposed_fields`
reports state outside the capture's visible cells.

- `preceding_graphic` is the glyph that a following REP (`CSI Ps b`) repeats.
  A cursor movement can clear it without changing the visible cells.
- `grapheme_continuation` is the state used to join a following combining
  mark or emoji component to the preceding glyph.
- `utf8_prefix` is an incomplete UTF-8 code point at the checkpoint.

{class}`~libvt.contrib.tmux.control.TmuxPaneSync` feeds the pending escape
bytes tmux returns through `capture-pane -P -C`. The native command can
return an empty prefix while the UTF-8 decoder still has buffered bytes.
Resume from a known input boundary when continuation must be exact. A
redraw that supplies complete encoded text and establishes its own first
graphic can serve as that checkpoint.

```{eval-rst}
.. automodule:: libvt.contrib.tmux.capture
   :members:
   :no-private-members:
   :exclude-members: CaptureInput

.. py:type:: CaptureInput
   :module: libvt.contrib.tmux.capture
   :canonical: str | bytes | bytearray | collections.abc.Sequence[str]

   Accepted input representation for ``tmux capture-pane`` lines or raw text.
```
