Skip to content

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

Open
armorbreak001 wants to merge 1 commit intoTextualize:masterfrom
armorbreak001:fix/ansi-decoder-crlf
Open

fix(ansi): handle CRLF line endings in AnsiDecoder.decode#4091
armorbreak001 wants to merge 1 commit intoTextualize:masterfrom
armorbreak001:fix/ansi-decoder-crlf

Conversation

@armorbreak001
Copy link
Copy Markdown

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

CRLF line endings left a bare \r after rstripping \n, which
decode_line then consumed via rsplit('\\r', 1)[-1], yielding
empty strings for every line.
@willmcgugan
Copy link
Copy Markdown
Member

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

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.

[BUG] Text.from_ansi leaves empty lines when input string has CRLF line endings

2 participants