Skip to content

Commit 61ebf75

Browse files
authored
contrib(feat[tmux]): Split tmux into contrib (#47)
why: Coupling tmux capture and profile logic inside core libvt blocked other multiplexer integrations and forced eager terminal imports. what: - Move tmux integration into decoupled libvt.contrib.tmux.profile, capture, and control submodules behind a PEP 562 package root - Gate tmux_profile DECRQSS on tmux >= 3.6 and parameterize DA1 on sixel and clipboard capabilities - Flag uncalibrated tab stops in CaptureCompleteness and enforce zero core-to-contrib imports
2 parents 7d4efd0 + 3975ac0 commit 61ebf75

23 files changed

Lines changed: 880 additions & 353 deletions

‎AGENTS.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ what was asked for.
1616

1717
| Path | What it is |
1818
| ---- | ---------- |
19-
| `src/libvt/parser.py`, `modes.py`, `style.py`, `config.py` | VT500 byte parser, CSI subparameters, modes, SGR styles, and `Profile` / `Policy` / `Limits` |
19+
| `src/libvt/parser.py`, `modes.py`, `style.py`, `config.py`, `profiles.py` | VT500 byte parser, CSI subparameters, modes, SGR styles, `Profile` / `Policy` / `Limits`, and host presets |
2020
| `src/libvt/_ucd.py`, `_grid.py`, `screen.py`, `terminal.py` | Unicode 17 width/clustering tables, packed viewport & RLE scrollback rows, `Screen` / `ScreenSet`, `Terminal`, `Snapshot`, and `Formatter` |
21-
| `src/libvt/status.py`, `events.py`, `input.py`, `codec.py` | Rex `OSC 7501` program status store, closed `Event` union, mode-aware input encoders, and cold-path VT sequence explainer |
22-
| `src/libvt/graphics.py`, `tmux.py` | Zero-dependency `SIXEL` / Kitty `APC G` placement tracker and `tmux capture-pane` / `-CC` decoders |
21+
| `src/libvt/status.py`, `events.py`, `input.py`, `codec.py` | Rex `OSC 7501` program status store, open `Event` hierarchy, mode-aware input encoders, and cold-path VT sequence explainer |
22+
| `src/libvt/graphics.py`, `contrib/tmux/` | Zero-dependency `SIXEL` / Kitty `APC G` placement tracker and decoupled `tmux` `profile` / `capture` / `control` modules |
2323
| `src/libvt/aio.py`, `__main__.py` | `AsyncTerminalStream`, POSIX `open_pty()`, and `python -m libvt` CLI (`explain`, `render`, `strip`) |
2424
| `src/libvt/testing.py`, `pytest_plugin.py`, `exc.py` | Boxed `assert_screen`, `FlightRecorder` diagnostics, `vt_*` pytest fixtures, and exceptions |
2525
| `tests/` | Functional, property-fuzz, PTY, CLI, and fixture tests organized by module under test |

‎CHANGES‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ _Notes on the upcoming release will go here._
88

99
### Breaking changes
1010

11+
#### Decoupled `libvt.contrib.tmux` submodules and core `tmux` removal (#39)
12+
13+
`libvt.tmux`, `Terminal.from_tmux_capture()`, `Snapshot.from_tmux_capture()`,
14+
`Profile.tmux()`, {data}`~libvt.contrib.tmux.profile.TMUX_PROFILE`, and
15+
{data}`~libvt.contrib.tmux.profile.TMUX_CAPTURE_POLICY` move into
16+
decoupled {mod}`libvt.contrib.tmux` submodules
17+
({mod}`libvt.contrib.tmux.profile`, {mod}`libvt.contrib.tmux.capture`, and
18+
{mod}`libvt.contrib.tmux.control`) with {func}`~libvt.contrib.tmux.profile.tmux_profile`
19+
accepting `sixel` and `clipboard` `DA1` flags:
20+
21+
```python
22+
# Before
23+
from libvt import TMUX_PROFILE, Terminal
24+
25+
term = Terminal.from_tmux_capture(lines, metadata=meta)
26+
27+
# After
28+
from libvt.contrib.tmux.capture import decode_tmux_capture
29+
from libvt.contrib.tmux.profile import TMUX_PROFILE, tmux_profile
30+
31+
term = decode_tmux_capture(lines, metadata=meta).terminal
32+
```
33+
1134
#### Open `Event` base class and consolidated `TitleChanged` (#38)
1235

1336
{class}`~libvt.events.Event` is now an open keyword-only base class

‎MIGRATION‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@ downstream projects (and `>=0.x,<0.y` once `0.1.0` is released).
1414
_Detailed migration steps for the next version will be posted here._
1515
<!-- END PLACEHOLDER - ADD NEW MIGRATION ENTRIES BELOW THIS LINE -->
1616

17+
### `libvt.contrib.tmux` submodules and `from_tmux_capture` removal (#39)
18+
19+
`tmux` profiles, `capture-pane` decoders, and `-CC` control-mode unescaping now
20+
live in decoupled {mod}`libvt.contrib.tmux.profile`,
21+
{mod}`libvt.contrib.tmux.capture`, and {mod}`libvt.contrib.tmux.control`
22+
submodules (re-exported lazily on {mod}`libvt.contrib.tmux`), and core
23+
{class}`~libvt.terminal.Terminal` / {class}`~libvt.terminal.Snapshot` no longer
24+
carry `from_tmux_capture` constructors:
25+
26+
```python
27+
# Before
28+
from libvt import Profile, Snapshot, Terminal
29+
from libvt.tmux import build_tmux_capture_command, unescape_tmux_control_output
30+
31+
prof = Profile.tmux("3.9")
32+
term = Terminal.from_tmux_capture(lines, metadata=meta)
33+
snap = Snapshot.from_tmux_capture(lines, metadata=meta)
34+
35+
# After
36+
from libvt.contrib.tmux.capture import (
37+
build_tmux_capture_command,
38+
decode_tmux_capture,
39+
)
40+
from libvt.contrib.tmux.control import unescape_tmux_control_output
41+
from libvt.contrib.tmux.profile import tmux_profile
42+
43+
prof = tmux_profile("3.9")
44+
res = decode_tmux_capture(lines, metadata=meta)
45+
term, snap = res.terminal, res.snapshot
46+
```
47+
1748
### Open `Event` hierarchy and `WindowRenamed` consolidation (#38)
1849

1950
All event classes in {mod}`libvt.events` inherit from the open keyword-only

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ wide-character column alignment, and cursor coordinates in tests:
9090
- Run terminal programs on POSIX PTYs or connect to `asyncio` streams.
9191

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

9696
## License
9797

‎docs/api/contrib_tmux.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# `libvt.contrib.tmux`
2+
3+
```{eval-rst}
4+
.. py:module:: libvt.contrib
5+
6+
.. automodule:: libvt.contrib.tmux
7+
:no-members:
8+
```
9+
10+
## `libvt.contrib.tmux.profile`
11+
12+
```{eval-rst}
13+
.. automodule:: libvt.contrib.tmux.profile
14+
:members:
15+
:no-private-members:
16+
```
17+
18+
## `libvt.contrib.tmux.capture`
19+
20+
```{eval-rst}
21+
.. automodule:: libvt.contrib.tmux.capture
22+
:members:
23+
:no-private-members:
24+
:exclude-members: CaptureInput
25+
26+
.. py:type:: CaptureInput
27+
:module: libvt.contrib.tmux.capture
28+
:canonical: str | bytes | bytearray | collections.abc.Sequence[str]
29+
30+
Accepted input representation for ``tmux capture-pane`` lines or raw text.
31+
```
32+
33+
## `libvt.contrib.tmux.control`
34+
35+
```{eval-rst}
36+
.. automodule:: libvt.contrib.tmux.control
37+
:members:
38+
:no-private-members:
39+
```

‎docs/api/index.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ Mode-aware `KeyEvent`, `MouseEvent`, `PasteEvent`, and VT sequence `explain`.
6464
`SIXEL` and Kitty `APC G` `ImageMeta` and `ImagePlacement`.
6565
:::
6666

67-
:::{grid-item-card} `libvt.tmux`
68-
:link: tmux
67+
:::{grid-item-card} `libvt.contrib.tmux`
68+
:link: contrib_tmux
6969
:link-type: doc
70-
`build_tmux_capture_command`, `decode_tmux_capture`, and `-CC` unescaping.
70+
Decoupled `tmux_profile`, `decode_tmux_capture`, and `-CC` unescaping submodules.
7171
:::
7272

7373
::::
@@ -114,7 +114,7 @@ status
114114
input
115115
codec
116116
graphics
117-
tmux
117+
contrib_tmux
118118
aio
119119
testing
120120
pytest_plugin

‎docs/api/tmux.md‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎docs/redirects.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"api/tmux" "api/contrib_tmux"

‎docs/topics/architecture.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ bytes. The caller provides incoming data, retrieves queued replies with
1414
{meth}`~libvt.terminal.Terminal.drain_replies`, and decides when to read or
1515
write the transport (a sans-I/O boundary).
1616

17-
Importing `libvt` loads the emulation, input, formatting, and `tmux` modules.
18-
{mod}`libvt.aio`, {mod}`libvt.testing`, and {mod}`libvt.pytest_plugin` are
19-
imported separately when used, and POSIX `pty` / `termios` modules are loaded
20-
inside {func}`~libvt.aio.open_pty`.
17+
Importing `libvt` loads core emulation, input, and formatting modules while
18+
keeping peer integrations under {mod}`libvt.contrib`. {mod}`libvt.aio`,
19+
{mod}`libvt.testing`, and {mod}`libvt.pytest_plugin` are imported separately
20+
when used, and POSIX `pty` / `termios` modules are loaded inside
21+
{func}`~libvt.aio.open_pty`.
2122

2223
## Configuration
2324

@@ -28,10 +29,11 @@ data:
2829

2930
```python
3031
>>> import libvt
32+
>>> from libvt.contrib.tmux.profile import TMUX_PROFILE
3133
>>> term = libvt.Terminal(
3234
... rows=3,
3335
... cols=5,
34-
... profile=libvt.TMUX_PROFILE,
36+
... profile=TMUX_PROFILE,
3537
... policy=libvt.Policy(strict=False),
3638
... limits=libvt.Limits(max_osc_bytes=8192),
3739
... )

‎src/libvt/__init__.py‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
DEFAULT_OSC7_HOSTS,
3131
DEFAULT_POLICY,
3232
DEFAULT_PROFILE,
33-
TMUX_CAPTURE_POLICY,
34-
TMUX_PROFILE,
3533
AmbiguousWidth,
3634
Charset,
3735
ColorScheme,
@@ -148,19 +146,6 @@
148146
render,
149147
strip,
150148
)
151-
from libvt.tmux import (
152-
TMUX_METADATA_FORMAT,
153-
CaptureCompleteness,
154-
CaptureInput,
155-
TmuxCaptureCommand,
156-
TmuxCaptureResult,
157-
TmuxLineFlags,
158-
TmuxPaneMetadata,
159-
build_tmux_capture_command,
160-
decode_tmux_capture,
161-
parse_flagged_line,
162-
unescape_tmux_control_output,
163-
)
164149

165150
logging.getLogger(__name__).addHandler(logging.NullHandler())
166151

@@ -174,17 +159,12 @@
174159
"GHOSTTY_PROFILE",
175160
"KITTY_PROFILE",
176161
"LINUX_CONSOLE_PROFILE",
177-
"TMUX_CAPTURE_POLICY",
178-
"TMUX_METADATA_FORMAT",
179-
"TMUX_PROFILE",
180162
"UNICODE_VERSION",
181163
"XTERM_PROFILE",
182164
"AmbiguousWidth",
183165
"AnsiColor",
184166
"Bell",
185167
"BlockKind",
186-
"CaptureCompleteness",
187-
"CaptureInput",
188168
"Cell",
189169
"Charset",
190170
"ClipboardWrite",
@@ -271,10 +251,6 @@
271251
"TerminalTimeoutError",
272252
"TitleChanged",
273253
"TitleTarget",
274-
"TmuxCaptureCommand",
275-
"TmuxCaptureResult",
276-
"TmuxLineFlags",
277-
"TmuxPaneMetadata",
278254
"UnderlineStyle",
279255
"UnhandledSequence",
280256
"UnicodeBehavior",
@@ -294,18 +270,14 @@
294270
"__title__",
295271
"__tracker__",
296272
"__version__",
297-
"build_tmux_capture_command",
298-
"decode_tmux_capture",
299273
"display_width",
300274
"encode_input",
301275
"encode_paste",
302276
"explain",
303277
"format_explain",
304278
"is_safe_paste",
305-
"parse_flagged_line",
306279
"parse_sgr",
307280
"render",
308281
"sanitize_terminal_text",
309282
"strip",
310-
"unescape_tmux_control_output",
311283
]

0 commit comments

Comments
 (0)