Skip to content

_pyrepl: switch console refresh to structured rendered screens#146584

Open
pablogsal wants to merge 8 commits intopython:mainfrom
pablogsal:pyrepl-new
Open

_pyrepl: switch console refresh to structured rendered screens#146584
pablogsal wants to merge 8 commits intopython:mainfrom
pablogsal:pyrepl-new

Conversation

@pablogsal
Copy link
Copy Markdown
Member

@pablogsal pablogsal commented Mar 28, 2026

No description provided.

Introduce render-cell, rendered-screen, and line-diff helpers for redraw work.
Keep the new abstractions self-contained so later commits can adopt them cleanly.
Teach the reader and terminal backends to refresh from RenderedScreen objects.
This isolates the redraw-planning refactor before layout and styling changes land.
Add structured prompt, content, and wrapped-row helpers for screen calculation.
Move reader layout bookkeeping onto those helpers before styling changes arrive.
Thread StyleRef and styled content fragments through render and reader paths.
Keep semantic color information attached to cells during redraw diffs.
Make buffer, layout, prompt, overlay, and full redraw causes explicit in Reader.
The invalidation matrix is still cursed, but at least now it is visible.
Move completion and message UI onto overlays layered over the base rendered screen.
The completion menu stops pretending it is the base reality.
@pablogsal pablogsal changed the title _pyrepl: fix multiline history recall and sanitize NULs in history files _pyrepl: switch console refresh to structured rendered screens Mar 28, 2026
@pablogsal pablogsal force-pushed the pyrepl-new branch 2 times, most recently from f7c4493 to 7c26e18 Compare March 30, 2026 22:18
Finish the refactor with prompt-cell caching, typed aliases, and layout edge-case fixes.
Land the remaining render and reader regressions needed for the final shape.
@pablogsal pablogsal marked this pull request as ready for review March 31, 2026 18:39
@pablogsal pablogsal requested review from Copilot and removed request for ambv and lysnikolaou March 31, 2026 18:40
@pablogsal
Copy link
Copy Markdown
Member Author

Crap I activated this copilot nonsense by mistake ...

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors _pyrepl screen refresh to operate on structured “rendered screens” (cells/lines + cursor) rather than raw string lists, with corresponding updates to console backends and tests.

Changes:

  • Introduces structured rendering/layout primitives (RenderCell/RenderLine/RenderedScreen, LayoutMap, content fragments) and updates Reader to produce/compose them.
  • Rewrites Unix/Windows console refresh() paths to diff/apply RenderedScreen updates via explicit refresh plans.
  • Updates tests and ancillary behavior (e.g., control-char display escaping and history-file NUL sanitization) to match the new rendering model.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Lib/_pyrepl/render.py New rendering model (cells/lines/screens), diffing, and line-update primitives.
Lib/_pyrepl/layout.py New layout mapping between buffer positions and rendered rows/columns.
Lib/_pyrepl/content.py New prompt/body content modeling and buffer-to-fragment conversion.
Lib/_pyrepl/reader.py Major refactor: invalidation model, rendered screen composition, and layout-driven cursor mapping.
Lib/_pyrepl/unix_console.py Refresh rewritten to plan/apply structured line updates; fixes raw accumulation bug.
Lib/_pyrepl/windows_console.py Refresh rewritten to plan/apply structured line updates with rendered state sync.
Lib/_pyrepl/console.py Console API now refreshes with RenderedScreen; adds rendered-state sync + redraw visualization.
Lib/_pyrepl/utils.py Adds display-char iterator/control escaping helpers; refactors disp_str; adds StyleRef.
Lib/_pyrepl/types.py Expands shared type aliases (cursor/dimensions/keymap/event data).
Lib/_pyrepl/trace.py Adds trace_text() helper for safer trace output.
Lib/_pyrepl/readline.py Sanitizes embedded NULs when reading history; updates overlay invalidation hooks.
Lib/_pyrepl/commands.py Converts “dirty” flag usage to targeted invalidations; updates screen sync behavior.
Lib/_pyrepl/completing_reader.py Moves completions menu to overlay-based composition; updates invalidations.
Lib/_pyrepl/historical_reader.py Updates history operations to invalidate buffer/prompt appropriately.
Lib/_pyrepl/simple_interact.py Switches interrupt path to full invalidation.
Lib/_pyrepl/input.py Cleans up TYPE_CHECKING guard for type-only imports.
Lib/test/test_pyrepl/support.py Test utilities updated for rendered-line equality and new console refresh signature.
Lib/test/test_pyrepl/test_reader.py Adds/adjusts tests for control-byte escaping, zero-width behavior, and layout mapping.
Lib/test/test_pyrepl/test_unix_console.py Adds regression test for colorized multiline typing redraw behavior.
Lib/test/test_pyrepl/test_windows_console.py Updates expected cursor movement/write patterns due to new refresh diffing.
Lib/test/test_pyrepl/test_pyrepl.py Adds history/NUL sanitization test and multiline history navigation behavior updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +422 to +427
source_lines = self._build_source_lines(offset, num_common_lines)
content_lines = self._build_content_lines(
source_lines,
offset,
prompt_from_cache=bool(offset and self.buffer[offset - 1] != "\n"),
)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calc_screen() passes num_common_lines (which is derived from cached render/layout rows) as first_lineno into _build_source_lines(). That lineno is later passed to get_prompt(), but get_prompt() expects a logical buffer line number (based on \n count), not a rendered-row count. When the cache boundary falls mid-wrapped line (or after multi-line prompt leading rows), this can shift lineno and cause incorrect prompt selection (e.g. using ps3 where ps4 should apply). Consider computing first_lineno from the buffer (e.g. number of \n before offset) or caching a separate logical-line counter alongside line_end_offsets.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants