Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 58 additions & 48 deletions CHANGES

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions MIGRATION
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ the next character matters.

### VT snapshot output retains the terminal pen

{meth}`~libvt.terminal.Snapshot.format` with
{attr}`~libvt.terminal.OutputFormat.VT` ends with the captured pen and
{meth}`~libvt.snapshot.Snapshot.format` with
{attr}`~libvt.format.OutputFormat.VT` ends with the captured pen and
cursor state. When appending unrelated text, set its cursor position
and rendition before writing. Close a captured OSC 8 hyperlink with
`OSC 8 ; ; ST` and reset SGR and DECSCA with `CSI 0 m` and `CSI 0 " q`.
Expand Down Expand Up @@ -175,7 +175,7 @@ regenerate affected `.ambr` expectations with `pytest --snapshot-update`.

{meth}`~libvt.aio.AsyncTerminalStream.wait_for` and
{meth}`~libvt.aio.PtySession.wait_for` match strings against
{attr}`~libvt.terminal.Snapshot.unwrapped_text`. Replace a string that includes
{attr}`~libvt.snapshot.Snapshot.unwrapped_text`. Replace a string that includes
a soft-wrap boundary with a callable that inspects the physical rows.

```python
Expand All @@ -191,11 +191,11 @@ await session.wait_for(lambda snap: "hello wo\nrld" in snap.text)
### Curated PEP 562 `libvt` root exports (#43)

Top-level {mod}`libvt` now exports only {class}`~libvt.style.Appearance`,
{class}`~libvt.screen.Cell`, {class}`~libvt.events.Event`,
{class}`~libvt.views.Cell`, {class}`~libvt.events.Event`,
{exc}`~libvt.exc.LibVtError`, {class}`~libvt.config.Limits`,
{class}`~libvt.config.Policy`, {class}`~libvt.config.Profile`,
{exc}`~libvt.exc.ProtocolError`, {class}`~libvt.screen.Screen`,
{class}`~libvt.terminal.Snapshot`, {class}`~libvt.style.Style`,
{class}`~libvt.snapshot.Snapshot`, {class}`~libvt.style.Style`,
{class}`~libvt.terminal.Terminal`, `__version__`,
{func}`~libvt.terminal.render`, and {func}`~libvt.terminal.strip` via lazy PEP
562 attribute lookup. Import modes, styles, events, parsers, input encoders, and
Expand Down Expand Up @@ -241,7 +241,7 @@ pol = Policy(clipboard_read=ClipboardReadPolicy.IGNORE)
live in decoupled {mod}`libvt.contrib.tmux.profile`,
{mod}`libvt.contrib.tmux.capture`, and {mod}`libvt.contrib.tmux.control`
submodules (re-exported lazily on {mod}`libvt.contrib.tmux`), and core
{class}`~libvt.terminal.Terminal` / {class}`~libvt.terminal.Snapshot` no longer
{class}`~libvt.terminal.Terminal` / {class}`~libvt.snapshot.Snapshot` no longer
carry `from_tmux_capture` constructors:

```python
Expand Down Expand Up @@ -361,11 +361,11 @@ cap_term = Terminal.from_tmux_capture(["\x1b[5:3moverline\x1b[0m"])

### Opaque `SyncToken` watermarks (#22)

{class}`~libvt.terminal.SyncToken` no longer exposes internal watermark fields
{class}`~libvt.snapshot.SyncToken` no longer exposes internal watermark fields
or direct construction; obtain tokens from
{meth}`~libvt.terminal.Terminal.sync_token` or
{attr}`~libvt.terminal.ScreenDelta.token` and inspect terminal state via
{attr}`~libvt.terminal.ScreenDelta.snapshot`:
{attr}`~libvt.snapshot.ScreenDelta.token` and inspect terminal state via
{attr}`~libvt.snapshot.ScreenDelta.snapshot`:

```python
# Before
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ styles:
- Run terminal programs on POSIX PTYs or connect to `asyncio` streams.

Read `tmux` captures as screen cells and decode control-mode output with
[`libvt.contrib.tmux`](https://libvt.git-pull.com/api/contrib_tmux/). Full
[`libvt.contrib.tmux`](https://libvt.git-pull.com/api/contrib/tmux/). Full
guides and API reference are at [libvt.git-pull.com](https://libvt.git-pull.com/).

## License
Expand All @@ -215,11 +215,11 @@ MIT License. See [LICENSE](LICENSE).

[feed]: https://libvt.git-pull.com/api/terminal/#libvt.terminal.Terminal.feed
[committed]: https://libvt.git-pull.com/api/terminal/#libvt.terminal.Terminal.committed
[viewport]: https://libvt.git-pull.com/api/terminal/#libvt.terminal.Snapshot.viewport
[viewport]: https://libvt.git-pull.com/api/snapshot/#libvt.snapshot.Snapshot.viewport
[assert_screen_box]: https://libvt.git-pull.com/api/testing/#libvt.testing.assert_screen_box
[contrib_syrupy]: https://libvt.git-pull.com/api/contrib_syrupy/
[contrib_syrupy]: https://libvt.git-pull.com/api/contrib/syrupy/
[pytest_plugin]: https://libvt.git-pull.com/api/pytest_plugin/
[vt_snapshot]: https://libvt.git-pull.com/api/contrib_syrupy/#libvt.contrib.syrupy.vt_snapshot
[vt_snapshot]: https://libvt.git-pull.com/api/contrib/syrupy/#libvt.contrib.syrupy.vt_snapshot
[vt_screen]: https://libvt.git-pull.com/api/testing/#libvt.testing.vt_screen
[serialize_vt_snapshot]: https://libvt.git-pull.com/api/testing/#libvt.testing.serialize_vt_snapshot
[render]: https://libvt.git-pull.com/api/terminal/#libvt.terminal.render
Expand Down
14 changes: 0 additions & 14 deletions docs/api/aio.md

This file was deleted.

21 changes: 21 additions & 0 deletions docs/api/aio/core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# `libvt.aio` — Session Core

Shared session protocol, reply writer protocol, and PTY line discipline type
exported from {mod}`libvt.aio`.

```{eval-rst}
.. py:currentmodule:: libvt.aio

.. autoclass:: AsyncSession
:members:
:no-show-inheritance:

.. autoclass:: ReplyWriter
:members:
:no-show-inheritance:

.. py:type:: TtyMode
:canonical: typing.Literal["cooked", "cbreak", "raw"]

Slave pseudo-terminal line discipline mode passed to :func:`open_pty`.
```
42 changes: 42 additions & 0 deletions docs/api/aio/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# `libvt.aio`

`asyncio` stream and POSIX PTY adapters over {class}`~libvt.terminal.Terminal`.

::::{grid} 1 1 3 3
:gutter: 2

:::{grid-item-card} Session Core
:link: core
:link-type: doc
{class}`~libvt.aio.AsyncSession`, {class}`~libvt.aio.ReplyWriter`, and
{obj}`~libvt.aio.TtyMode`.
:::

:::{grid-item-card} Async Stream
:link: stream
:link-type: doc
{class}`~libvt.aio.AsyncTerminalStream` for `asyncio` stream transports.
:::

:::{grid-item-card} POSIX PTY
:link: pty
:link-type: doc
{func}`~libvt.aio.open_pty` and {class}`~libvt.aio.PtySession` for child
processes in a pseudo-terminal.
:::

::::

```{eval-rst}
.. automodule:: libvt.aio
:no-members:
```

```{toctree}
:hidden:
:maxdepth: 1

core
stream
pty
```
14 changes: 14 additions & 0 deletions docs/api/aio/pty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# `libvt.aio` — POSIX PTY

POSIX pseudo-terminal subprocess adapter exported from {mod}`libvt.aio`.

```{eval-rst}
.. py:currentmodule:: libvt.aio

.. autoclass:: PtySession
:members:
:inherited-members:
:no-show-inheritance:

.. autofunction:: open_pty
```
12 changes: 12 additions & 0 deletions docs/api/aio/stream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# `libvt.aio` — Async Stream

`asyncio` stream transport adapter exported from {mod}`libvt.aio`.

```{eval-rst}
.. py:currentmodule:: libvt.aio

.. autoclass:: AsyncTerminalStream
:members:
:inherited-members:
:no-show-inheritance:
```
34 changes: 34 additions & 0 deletions docs/api/contrib/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# `libvt.contrib`

Optional ecosystem integrations kept separate from the zero-dependency VT core.

::::{grid} 1 1 2 2
:gutter: 2

:::{grid-item-card} `libvt.contrib.tmux`
:link: tmux/index
:link-type: doc
Decoupled `tmux` profiles, `capture-pane` decoders, multi-pane window
compositing, and `-C` / `-CC` control-mode synchronization.
:::

:::{grid-item-card} `libvt.contrib.syrupy`
:link: syrupy
:link-type: doc
Optional `syrupy` `.ambr` golden adapter and conditional `vt_snapshot`
fixture (`libvt[syrupy]`).
:::

::::

```{eval-rst}
.. py:module:: libvt.contrib
```

```{toctree}
:hidden:
:maxdepth: 2

tmux/index
syrupy
```
2 changes: 1 addition & 1 deletion docs/api/contrib_syrupy.md → docs/api/contrib/syrupy.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uninstalled or disabled via `-p no:syrupy`):
>>> test_tui_banner(_VerifyAmbr()) # doctest: +HIDE
```

See {doc}`../topics/testing` for using
See {doc}`../../topics/testing` for using
{func}`~libvt.testing.serialize_vt_snapshot` and {func}`~libvt.testing.vt_screen`
without `syrupy`, or sharing row scrubbers with
{meth}`VtSnapshotExtension.configure <libvt.contrib.syrupy.VtSnapshotExtension.configure>`.
Expand Down
65 changes: 65 additions & 0 deletions docs/api/contrib/tmux/capture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# `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.
```
56 changes: 56 additions & 0 deletions docs/api/contrib/tmux/control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# `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`.
```
Loading
Loading