refactor: extract rich_utils; stop monkey-patching Rich's Markdown globally#20
Merged
Conversation
…obally Move the Rich/Pygments helpers (_is_rich_renderable, _rich_to_ansi, _renderable_to_ansi, _markdown_to_ansi, _highlight_code) out of display.py into rich_utils.py. types.py previously had to import these from display at function level to dodge a cycle — a low-level module reaching up into the display layer. display.py re-exports the names for backward compatibility. The left-aligned heading style was applied by replacing Markdown.elements['heading_open'] at import time, which changed heading rendering for the host application's own Rich usage. It is now a scoped Markdown subclass used only by our markdown rendering; rich.markdown.Markdown is left untouched.
…_output Neither method has a production caller: the session-level binding (via ThinkingBoxManager) owns expand/collapse, and Display.thinking() owns console truncation. get_key_bindings also shadowed the UIControl.get_key_bindings() API with an incompatible signature and built a fresh KeyBindings object per call. Tests that existed only to exercise the dead methods are removed with them.
The same frame tuple was duplicated in layout.py and app_info.py. It now lives in types.py (which imports nothing from the package); layout re-exports it for backward compatibility and AppInfo uses it as the field default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
rich_utilsmodule — the Rich/Pygments helpers move out ofdisplay.py(which re-exports the old names for backward compatibility). This removes the one inverted edge in the module graph:types.pyno longer needs function-level imports from the display layer. Publicrich_to_ansiexport unchanged.thinking_promptno longer replacesMarkdown.elements['heading_open']process-wide (which changed heading rendering for the host application's own Rich usage). The left-aligned style is now an internalMarkdownsubclass used only by this library's markdown rendering; a regression test pinsrich.markdown.Markdownas untouched.ThinkingBoxControl.get_key_bindings()/get_console_output()had no production callers (the session-level binding owns expand/collapse;Display.thinking()owns console truncation), andget_key_bindingsshadowed theUIControlAPI with an incompatible signature. Their tests-only coverage is removed with them.DEFAULT_SPINNER_FRAMESdeduped — single source of truth intypes.py(still importable fromlayout);AppInfo.thinking_animationdefaults to it.Identified in docs/notes/project_review_20260612.md (finding 2 + structure improvements).