Skip to content

Fix ANSI colors stripped when TERM=dumb or color system undetectable#1629

Closed
Nilsonfsilva wants to merge 2 commits intopython-cmd2:mainfrom
Nilsonfsilva:fix-ansi-color-dumb-terminal-v2
Closed

Fix ANSI colors stripped when TERM=dumb or color system undetectable#1629
Nilsonfsilva wants to merge 2 commits intopython-cmd2:mainfrom
Nilsonfsilva:fix-ansi-color-dumb-terminal-v2

Conversation

@Nilsonfsilva
Copy link
Copy Markdown

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

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
Copy link
Copy Markdown

codecov bot commented Apr 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.48%. Comparing base (ea66804) to head (3d1239a).
⚠️ Report is 1 commits behind head on main.

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     
Flag Coverage Δ
unittests 99.48% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Member

@tleonhardt tleonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread cmd2/rich_utils.py
force_terminal: bool | None = None
force_interactive: bool | None = None

color_system: str | None = "auto"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hint for color_system should be Literal['auto', 'standard', '256', 'truecolor', 'windows']

Will need to add Literal to imports from `typing.

@tleonhardt
Copy link
Copy Markdown
Member

@Nilsonfsilva cmd2 version 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?

@tleonhardt
Copy link
Copy Markdown
Member

tleonhardt commented Apr 13, 2026

PR #1634 made equivalent but more robust changes to the main branch while PR #1633 back-ported them to the 3.x branch, from which the 3.5.0 release was published to PyPI.

@Nilsonfsilva
Copy link
Copy Markdown
Author

Nilsonfsilva commented Apr 14, 2026 via email

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.

2 participants