fix(shell): prevent Rich default markdown styles from leaking background colors#1739
fix(shell): prevent Rich default markdown styles from leaking background colors#1739
Conversation
…ckground color leakage NEUTRAL_MARKDOWN_THEME inherits from Rich's defaults via inherit=True. Rich's built-in "markdown.code" and "markdown.code_block" styles include "on black" backgrounds that leak through on non-black terminals. Override all Rich markdown.* style keys to "none" so the custom _FALLBACK_STYLES control the final appearance. Closes #1681
There was a problem hiding this comment.
Pull request overview
This PR updates the shell’s Rich theme configuration to avoid Rich’s default Markdown styles introducing unintended background colors (notably for inline code and code blocks), and adds regression tests plus release-note entries documenting the fix.
Changes:
- Extend
NEUTRAL_MARKDOWN_THEMEto explicitly neutralize additionalmarkdown.*styles (includingmarkdown.code/markdown.code_block) to prevent inherited “on black” backgrounds. - Add unit tests asserting
markdown.code/markdown.code_blockhave no background color and attempting to guard against futuremarkdown.*background leakage. - Add Unreleased changelog entries (EN/ZH + root) documenting the rendering fix.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/kimi_cli/ui/shell/console.py |
Adds more markdown.* theme overrides to prevent Rich default Markdown backgrounds from leaking into shell rendering. |
tests/ui/test_console_theme.py |
Adds regression tests asserting the theme’s Markdown-related styles don’t set a background color. |
CHANGELOG.md |
Adds an Unreleased entry describing the Markdown black-background fix. |
docs/en/release-notes/changelog.md |
Mirrors the Unreleased changelog note in English docs. |
docs/zh/release-notes/changelog.md |
Mirrors the Unreleased changelog note in Chinese docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for name, style in NEUTRAL_MARKDOWN_THEME.styles.items(): | ||
| if name.startswith("markdown."): | ||
| assert style.bgcolor is None, ( | ||
| f"{name} should have no background color, got bgcolor={style.bgcolor}" | ||
| ) |
There was a problem hiding this comment.
test_all_markdown_styles_have_no_background() only iterates over NEUTRAL_MARKDOWN_THEME.styles, which contains only explicitly-defined overrides. This won’t catch cases where a markdown.* key is missing and a background color is inherited from Rich’s defaults (the main failure mode described in the docstring). Consider enumerating the markdown style names you rely on (e.g., from kimi_cli.utils.rich.markdown._FALLBACK_STYLES and any other markdown.* names used via markup) and asserting Console(theme=NEUTRAL_MARKDOWN_THEME).get_style(name).bgcolor is None for each, so missing overrides fail the test.
| "markdown.paragraph": "none", | ||
| "markdown.block_quote": "none", | ||
| "markdown.hr": "none", | ||
| "markdown.list": "none", | ||
| "markdown.item": "none", |
There was a problem hiding this comment.
The newly added overrides markdown.list, markdown.h7, and markdown.emph don’t appear to be referenced anywhere else in the codebase (search only finds them in this theme). If they’re intended purely as a defensive override against Rich internals, it would help to add a brief comment explaining why these keys are needed here; otherwise consider dropping unused keys to keep the theme definition aligned with actual style names we render.
…und colors (MoonshotAI#1739) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
markdown.*styles to"none"inNEUTRAL_MARKDOWN_THEMEto prevent background color leakage (e.g., black backgrounds on inline code and code blocks)markdown.*style carries a background colormarkdown.code("bold cyan on black") andmarkdown.code_block("cyan on black"); additional keys (markdown.emph,markdown.h7,markdown.list) are overridden as a defensive measureTest plan
markdown.codeandmarkdown.code_blockhave no bgcolormarkdown.*styles have no bgcolorCloses #1681