Fix ANSI colors stripped when TERM=dumb or color system undetectable#1629
Fix ANSI colors stripped when TERM=dumb or color system undetectable#1629Nilsonfsilva wants to merge 2 commits intopython-cmd2:mainfrom
Conversation
These patches were developed during Debian rebuild testing with Python 3.13, where all ANSI sequences were silently stripped even with ALLOW_STYLE=ALWAYS. The root cause is that Rich's _detect_color_system() returns None when TERM=dumb, overriding force_terminal=True. Debian build infrastructure always sets TERM=dumb to prevent interactive terminal usage during builds.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1629 +/- ##
==========================================
+ Coverage 99.46% 99.48% +0.02%
==========================================
Files 21 21
Lines 4697 4699 +2
==========================================
+ Hits 4672 4675 +3
+ Misses 25 24 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
There is a failing test on main that just started to fail because there is a new version of rich out that fixes a bug we were previously patching around.
@kmvanbrunt Can you please take care of fixing the failing test on master and requiring the newest version of rich with the fix?
| force_terminal: bool | None = None | ||
| force_interactive: bool | None = None | ||
|
|
||
| color_system: str | None = "auto" |
There was a problem hiding this comment.
Type hint for color_system should be Literal['auto', 'standard', '256', 'truecolor', 'windows']
Will need to add Literal to imports from `typing.
|
@Nilsonfsilva We fixed the issue here in a slightly different and more robust manner. Would you please be so kind as to let us know that fix meets the needs of your Debian release system? |
|
Hi everyone!
Thank you for your attention to the PR.
Answering your question:
Everything went well on the Debian side.
I hope this helps!
Nilson F. Silva
…________________________________
De: Todd Leonhardt ***@***.***>
Enviado: segunda-feira, 13 de abril de 2026 19:38
Para: python-cmd2/cmd2 ***@***.***>
Cc: Nilsonfsilva ***@***.***>; Mention ***@***.***>
Assunto: Re: [python-cmd2/cmd2] Fix ANSI colors stripped when TERM=dumb or color system undetectable (PR #1629)
[https://avatars.githubusercontent.com/u/2812720?s=20&v=4]tleonhardt left a comment (python-cmd2/cmd2#1629)<#1629 (comment)>
@Nilsonfsilva<https://github.com/Nilsonfsilva> cmd2 version 3.5.0<https://pypi.org/project/cmd2/3.5.0/> is now available on PyPI. It fixes the testing problem you reported here and also pins to an updated minimum version of rich since the new rich release fixed a bug that cmd2 had previously monkeypatched around.
We fixed the issue here in a slightly different and more robust manner. Would you please be so kind as to let us know that fix meets the needs of your Debian release system?
—
Reply to this email directly, view it on GitHub<#1629 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AVZIS7Y5B5O6JY3YZYQ3SFT4VVT6ZAVCNFSM6AAAAACXVWZTISVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DENBQGA3DKMZQHE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Hi!
@tleonhardt I have rebased the fix on top of the current main branch in a new branch fix-ansi-color-dumb-terminal-v2 and updated the PR accordingly. Please let me know if anything else is needed.
Nilson Silva