rich icon indicating copy to clipboard operation
rich copied to clipboard

fix(ansi): handle CRLF line endings in AnsiDecoder.decode

Open armorbreak001 opened this issue 7 months ago • 2 comments

When Text.from_ansi() receives a string with CRLF (\r\n) line endings, every line of content is lost — the result is all empty strings.

Root cause: AnsiDecoder.decode() splits on \n, strips trailing \n via .rstrip("\n"), then passes each line to decode_line(), which runs .rsplit("\r", 1)[-1] to handle terminal carriage-return overwrite semantics. When the input has CRLF endings, a bare \r remains after stripping; decode_line interprets that trailing \r as an overwrite and returns the (empty) portion after it.

Fix: strip trailing \r alongside \n in decode(): .rstrip("\n\r").

Reproduction:

from rich.text import Text
# Before fix: plain == '\\n\\n'  
# After fix:  plain == 'Hello\\nWorld\\n'
Text.from_ansi('Hello\\r\\nWorld\\r\\n').plain

Closes #4090

armorbreak001 avatar Apr 22 '26 15:04 armorbreak001

Your PR has been closed due to a AI policy violation.

Please read the following before submitting further PRs.

https://github.com/Textualize/textual/blob/main/AI_POLICY.md

willmcgugan avatar Apr 22 '26 15:04 willmcgugan

@willmcgugan

FYI, It appears that this PR is still open.

PureStupid avatar May 08 '26 10:05 PureStupid