Skip to content

refactor: extract rich_utils; stop monkey-patching Rich's Markdown globally#20

Merged
shoom1 merged 3 commits into
developfrom
refactor/rich-utils
Jun 12, 2026
Merged

refactor: extract rich_utils; stop monkey-patching Rich's Markdown globally#20
shoom1 merged 3 commits into
developfrom
refactor/rich-utils

Conversation

@shoom1

@shoom1 shoom1 commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Changes

  1. New rich_utils module — the Rich/Pygments helpers move out of display.py (which re-exports the old names for backward compatibility). This removes the one inverted edge in the module graph: types.py no longer needs function-level imports from the display layer. Public rich_to_ansi export unchanged.
  2. Scoped Rich heading style — importing thinking_prompt no longer replaces Markdown.elements['heading_open'] process-wide (which changed heading rendering for the host application's own Rich usage). The left-aligned style is now an internal Markdown subclass used only by this library's markdown rendering; a regression test pins rich.markdown.Markdown as untouched.
  3. Dead code removedThinkingBoxControl.get_key_bindings() / get_console_output() had no production callers (the session-level binding owns expand/collapse; Display.thinking() owns console truncation), and get_key_bindings shadowed the UIControl API with an incompatible signature. Their tests-only coverage is removed with them.
  4. DEFAULT_SPINNER_FRAMES deduped — single source of truth in types.py (still importable from layout); AppInfo.thinking_animation defaults to it.

Identified in docs/notes/project_review_20260612.md (finding 2 + structure improvements).

shoom1 added 3 commits June 12, 2026 13:15
…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.
@shoom1 shoom1 merged commit 68f0fa3 into develop Jun 12, 2026
@shoom1 shoom1 deleted the refactor/rich-utils branch June 12, 2026 20:08
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.

1 participant