Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

core(refactor): Split views, snapshot, dispatch, recorder, target, and aio (#203) - #204

Merged
tony merged 4 commits into
masterfrom
refactor/203-structural-split
Dec 5, 2026
Merged

tony merged 4 commits into
masterfrom
refactor/203-structural-split

Conversation

@tony

@tony tony commented Dec 5, 2026

Copy link
Copy Markdown
Member

Closes #203

Summary

Structural module split and protocol decoupling across core rendering, terminal state, testing target extraction, and asyncio transport layers — preserving all existing public imports and runtime compatibility while creating clean extension points for stacked concept PRs.

Atomic commits

  1. core(refactor): Extract views, format, snapshot
    • Extracts RowView/RegionView into libvt.views, Formatter/render/_render_vt into libvt.format, and Snapshot/SnapshotDict into libvt.snapshot, re-exported from libvt.screen and libvt.terminal.
    • Exposes is_private_mode_supported() in libvt.modes.
  2. terminal(refactor): Add slots, dispatch, recorder
    • Moves Terminal to __slots__ (78 slots, zero __dict__), splits VT handler tables into libvt._vt_dispatch, and adds TerminalRecorder protocol (libvt.recorder), Terminal._attach_recorder(), Terminal.replace_from(), and batched feed_until().
    • Migrates contrib/tmux/control.py off private terminal attribute mutation onto Terminal.replace_from().
  3. testing(refactor): Decouple SupportsVtTarget
    • Introduces SupportsVtTarget (__vt_target__) in libvt.testing and implements it on AsyncTerminalStream, PtySession, and TmuxCaptureResult, eliminating duck-typed _extract_target() chains.
    • Bumps test_live_tmux_server_vs_pure_terminal_snapshot_parity readiness wait loop to eliminate busy-runner startup timeout flakes.
  4. aio(refactor): Split package with _SessionCore
    • Splits libvt.aio into a package (aio/{__init__,_core,_stream,_pty}.py) sharing _SessionCore across AsyncTerminalStream and PtySession with zero runtime import cycles.

Verification

  • ruff check . and ruff format --check . (131 files)
  • ty check --python-version 3.12 and ty check --python-version 3.15
  • Runtime top-level import AST cycle audit (38 modules, 0 cycles)
  • pytest -q (1234 passed, 2 skipped)
  • sphinx-build -b html -W --keep-going docs (0 warnings)

tony added 3 commits December 5, 2026 08:31
why: Break the screen-to-terminal import cycle and separate low-level
buffer helpers, views, reflow, formatting, and snapshots into acyclic
modules.

what:
- Extract _util.py with hardened _byte_view and ASCII integer parsers
- Extract views.py with Cursor, ScrollRegion, RowView, and RegionView
- Extract _reflow.py for primary-screen soft-wrap reflow
- Extract format.py and snapshot.py, keeping terminal/screen re-exports
- Make screen.py acyclic with lazy graphics initialization
why: Bound Terminal memory with __slots__, move CSI/OSC/ESC/DCS dispatch
out of terminal.py, add a typed recorder seam without monkey-patching,
and centralize donor state transfer in replace_from.

what:
- Extract recorder.py with TerminalRecorder, FlightRecorder,
  CompositeRecorder, and find_flight_recorder
- Extract _vt_dispatch.py for CSI/OSC/ESC/DCS handling
- Add single-truth private mode support helpers in modes.py
- Add Terminal.__slots__, _attach_recorder, _attach_reply_sink,
  _resize_internal, batched feed_until recording, and replace_from
- Switch tmux control adoption to Terminal.replace_from
why: Remove libvt.testing's runtime dependency on contrib.tmux and
eliminate unsafe blind `.snapshot()` probing on arbitrary objects.

what:
- Add SupportsVtTarget (__vt_target__) guarded against class objects in
  testing.py and remove contrib.tmux imports and blind `.snapshot()`
- Implement __vt_target__ on TmuxCaptureResult, AsyncTerminalStream,
  and PtySession
- Widen pytest_plugin recorder annotations to TerminalRecorder | None
- Update docs/api/testing.md, migrate test_syrupy _SnapHolder, and
  widen live tmux capture polling iterations in test_testing.py
why: Deduplicate session sync-timer, input-encoding, reply-sink, and
wait_for logic across streams and PTYs while isolating POSIX PTY code
into its own module.

what:
- Replace aio.py with aio/__init__.py, _core.py, _stream.py, and
  _pty.py using relative imports and shared _SessionCore inheritance
- Preserve _FrameWaits, shared foreground stream reads, Linux pidfd
  process groups, cancel-safe close, and PTY fd cleanup on failure
- Document inherited members in docs/api/aio.md, update aio package
  loading in tests/test_aio.py, and record #203 in CHANGES
@tony
tony force-pushed the refactor/203-structural-split branch from e0cebb6 to fa5e1d2 Compare December 5, 2026 14:39
@tony
tony merged commit 380f369 into master Dec 5, 2026
9 checks passed
@tony
tony deleted the refactor/203-structural-split branch December 5, 2026 14:42
tony added a commit that referenced this pull request Dec 5, 2026
why: Decouple terminal views, formatting, snapshots, VT dispatch,
     recorders, testing targets, and asyncio transports so stacked
     extensions do not collide on monolithic modules or private fields.

what:
- Extract views, format, and snapshot modules from screen and terminal
- Add Terminal.__slots__, _vt_dispatch, TerminalRecorder, and
  Terminal.replace_from()
- Introduce SupportsVtTarget for testing target extraction
- Split libvt.aio into a package sharing _SessionCore
- core(refactor): Extract views, format, snapshot
- terminal(refactor): Add slots, dispatch, recorder
- testing(refactor): Decouple SupportsVtTarget
- aio(refactor): Split package with _SessionCore

Closes #203
tony added a commit that referenced this pull request Dec 5, 2026
why: Give every public module and split package its own API reference
     page after #204 and earlier contrib splits while preserving existing
     docs URLs through Sphinx rediraffe redirects.

what:
- Break docs/api/aio.md into docs/api/aio/{index,core,stream,pty}.md
- Break docs/api/contrib_tmux.md and contrib_syrupy.md into
  docs/api/contrib/{index,syrupy}.md and
  docs/api/contrib/tmux/{index,profile,capture,window,control}.md
- Add dedicated pages for views, snapshot, format, and recorder
- Scope screen.md and terminal.md to owned symbols and canonicalize
  cross-references across docs, docstrings, CHANGES, and MIGRATION
- Update docs/redirects.txt for moved API paths and add
  test_every_public_module_has_api_doc_page()

Refs #203

This branch was successfully deployed

1 active deployment
docs — fa5e1d2b Deployed Dec 5, 2026 by tony via build (3.14) #474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split terminal.py and screen.py, decouple contrib, restack PRs

1 participant