Repository navigation
Fix prompt-toolkit color names for Rich white and bright white - #1863
Conversation
ANSI_NAMES maps Rich's standard colors 0-15 to prompt-toolkit names. Color 7 (white, SGR 37) was mapped to "ansiwhite", which prompt-toolkit renders as bright white (SGR 97), and color 15 (bright white) was mapped to "ansibrightwhite", which prompt-toolkit does not know. A theme style using bright_white then made Style() raise "Wrong color format". Use "ansigray" for color 7 and "ansiwhite" for color 15.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1863 +/- ##
=======================================
Coverage 99.76% 99.76%
=======================================
Files 23 23
Lines 6777 6777
=======================================
Hits 6761 6761
Misses 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
Thanks for the fix and the regression tests, @mokshupadhyay. I reproduced both issues through cmd2’s The two replacements in I checked all 16 colors through the same theme API on this branch. Every foreground and background matched Rich’s terminal codes, including 37/47 for |
cmd2/pt_utils.pymaps Rich's 16 standard colors to prompt_toolkit color names with the tupleANSI_NAMES. prompt_toolkit's names for the last two are unusual: normal white (color 7, SGR 37) isansigray, and bright white (color 15, SGR 97) isansiwhite; it has noansibrightwhite. The tuple usedansiwhitefor color 7 (so a normal white was drawn as bright white) andansibrightwhitefor color 15, a name prompt_toolkit rejects.Real results (
prompt_toolkit.styles.base.ANSI_COLOR_NAMEScontainsansigrayandansiwhitebut notansibrightwhite), onmainand with this change:The fix changes those two entries of
ANSI_NAMESand explains the odd names in a comment.Tests:
test_rich_to_pt_color_white_is_not_bright_whiteandtest_rich_to_pt_color_standard_colors_are_valid(every standard color builds a valid prompt_toolkitStyle) intests/test_pt_utils.py; both fail onmainand pass now. The full suite passes (3231 passed, 5 skipped) andruff checkandruff format --checkare clean on the two changed files. I did not runmake checkormake docs-test, and I did not edit any Markdown file (AGENTS.md asks to ask first).