Skip to content

Preserve Unicode output with the Windows more pager - #1865

Merged
tleonhardt merged 3 commits into
python-cmd2:mainfrom
euno102:codex/windows-more-unicode
Dec 5, 2026
Merged

tleonhardt merged 3 commits into
python-cmd2:mainfrom
euno102:codex/windows-more-unicode

Conversation

@euno102

@euno102 euno102 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1845. Windows more.com can exit with status 0 after dropping a line of UTF-8 text. I reproduced this by piping a long CJK line into more.com with console code page 65001. The trailing marker was missing, while the same probe with ASCII retained it.

When ppaged() would use Windows more or more.com for non-ASCII output, it now writes the rendered text directly. If the output stream rejects a character, cmd2 displays its Unicode escape and preserves the surrounding text. This trades pagination for preserving the text in that case. ASCII output and configured alternative pagers still use the existing pager path. The scope is the external pager path, separate from the toolbar pager in #1814.

Validation

  • Windows: both regression cases failed before the fix and passed afterward. Full suite: 2,960 passed, 265 skipped.
  • Linux: make check, make test (3,218 passed, 7 skipped), and make docs-test passed.

AI disclosure: OpenAI Codex helped reproduce the issue, write the patch and regression tests, run validation, and draft this description.

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (90be3e7) to head (1cc2bdb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1865   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          23       23           
  Lines        6777     6785    +8     
=======================================
+ Hits         6761     6769    +8     
  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

Copy link
Copy Markdown
Member

Thanks, @euno102, for tracking this down and fixing it. Your reproduction showed why checking the exit code alone would miss the problem: more.com returned success even when it dropped the end of the line.

We added a follow-up in 1cc2bdb for interactive output streams that use a strict encoding such as CP1252. Bypassing more preserves the text on a UTF-8 terminal, but writing directly to a CP1252 stream could still raise UnicodeEncodeError and lose the whole line. If the stream rejects a character, ppaged() now displays its Unicode escape. The regression test checks that café 漢🙂 end comes through as café \u6f22\U0001f642 end on that stream, including the trailing text.

We also linked the PR to close #1845 on merge. Thanks again for the contribution!

@tleonhardt
tleonhardt merged commit bd4530a into python-cmd2:main Dec 5, 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: ppaged() shows nothing, or garbage, for long lines of non-ASCII text in more

2 participants