# `libvt.contrib.tmux.control`

A pane size change starts the same native refresh as
{meth}`~libvt.contrib.tmux.control.TmuxPaneSync.resync`. Send the commands
returned by {meth}`~libvt.contrib.tmux.control.TmuxPaneSync.handle_event` and
wait for `LIVE` before reading the new dimensions. The terminal keeps its
last frame until the new capture installs.

(tmux-row-bookmarks)=

## Keep a scrollback bookmark across updates

Store an absolute row with a {class}`~libvt.snapshot.SyncToken` from the
same terminal. A native refresh retains the current visible rows and the
requested history that tmux still holds. Once tmux has evicted earlier
history, the capture cannot recover the previous absolute origin. The
same row number may resolve to different text after a refresh.

```python
>>> from libvt import Terminal
>>> from libvt.terminal import ResyncReason, SyncToken
>>> def bookmarked_text(term: Terminal, token: SyncToken, row: int) -> str | None:
...     delta = term.changes_since(token)
...     expired = (ResyncReason.EPOCH_CHANGED, ResyncReason.TERMINAL_MISMATCH)
...     if delta.resync_reason in expired or delta.snapshot.active_is_alt:
...         return None
...     try:
...         return delta.snapshot.at_abs(row).text
...     except IndexError:
...         return None
>>> term = Terminal(rows=2, cols=8, scrollback=3)
>>> term.feed(b"r0\r\nr1\r\nr2")
>>> bookmark = (term.sync_token(), term.committed.scrolled_total + 1)
>>> bookmarked_text(term, *bookmark)
'r2'
>>> term.resize(rows=2, cols=10)
>>> bookmarked_text(term, *bookmark) is None
True
```

Use the same check with `sync.terminal` after a native tmux refresh.
An immutable snapshot retained with the bookmark still resolves rows in
its original frame.

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

.. py:type:: TmuxControlEvent
   :module: libvt.contrib.tmux.control
   :canonical: TmuxCommandBlock | TmuxOutput | TmuxExtendedOutput | TmuxPause | TmuxContinue | TmuxLayoutChange | TmuxSubscriptionChanged | TmuxExit | TmuxNotification

   Union of typed events emitted by :meth:`~libvt.contrib.tmux.control.TmuxControlParser.feed`.
```
