Draft
Fix stray ^M characters in subprocess output when redirected to file#462
Conversation
Copilot
AI
changed the title
[WIP] Fix linefeeds in craft-cli application output redirection
Fix stray ^M characters in subprocess output when redirected to file
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Subprocesses using bare
\rfor in-place terminal progress updates (e.g.Downloading 50%\rDownloading 100%\n) pass those carriage returns through_PipeReaderThread._write()unchanged. When the output stream is not a terminal (file redirect, pipe), the\rchars survive into the written text, producing^M-riddled output.Changes
craft_cli/messages.py— Normalize carriage returns in_PipeReaderThread._write()before line-splitting via a singlere.subpass:\r\n/\r+\n(Windows endings,\r\r\n) →\n(no extra blank lines)\r(in-place overwrites) →\n, so each update becomes its own lineb"\r" in dataguard skips regex entirely for the common CR-free casetests/unit/test_messages_stream_cm.py— Two new tests as reproducers:test_pipereader_carriage_returns:b"Step 1\rStep 2\rStep 3\n"→ three clean lines, no\rtest_pipereader_windows_line_endings:b"line1\r\nline2\r\n"→ two clean lines, no\r