Skip to content

Strip ANSI style sequences for external pager on legacy Windows console - #1854

Merged
tleonhardt merged 1 commit into
python-cmd2:mainfrom
PNHD:fix/strip-pager-style-legacy-windows
Dec 2, 2026
Merged

tleonhardt merged 1 commit into
python-cmd2:mainfrom
PNHD:fix/strip-pager-style-legacy-windows

Conversation

@PNHD

@PNHD PNHD commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

On a Windows console without VT processing, Cmd.ppaged() captures Rich output with ANSI SGR style sequences and pipes it to an external pager such as more. Unlike direct poutput() rendering through Rich's Win32 console renderer, Console.capture() still emits ANSI sequences even when console.legacy_windows is True, so more prints raw escape sequences as text.

This strips ANSI style sequences via su.strip_style() from the captured text sent to the external pager when console.legacy_windows is True, leaving VT consoles, Windows Terminal, and AllowStyle.NEVER behavior unchanged.

Tested locally on Windows 11 with Python 3.13.13:

  • uv run --no-project python -Xutf8 -m pytest tests -o "addopts=-n=auto --maxschedchunk=1": 2955 passed, 264 skipped (POSIX-only tests)
  • uv run --no-project ruff check cmd2/cmd2.py tests/test_cmd2.py and ruff format --check cmd2/cmd2.py tests/test_cmd2.py: passed
  • uv run --no-project mypy . and uv run --no-project ty check: passed

Fixes #1846

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (c76a501) to head (6c435c1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1854   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          23       23           
  Lines        6770     6773    +3     
=======================================
+ Hits         6754     6757    +3     
  Misses         16       16           
Flag Coverage Δ
unittests 99.76% <100.00%> (+<0.01%) ⬆️

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

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

@tleonhardt tleonhardt left a comment

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.

Thanks for the PR @PNHD

@tleonhardt
tleonhardt merged commit 6eb5e46 into python-cmd2:main Dec 2, 2026
28 checks passed
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.

Windows legacy console: ppaged() output in more shows escape sequences instead of colors

2 participants