fix: use LF instead of CRLF in insert_newline on Windows #1023
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.
LineBuffer::insert_newline()currently inserts CRLF (\r\n) on Windows and LF (\n) elsewhere.This change makes it always insert LF on all platforms.
Background
I use reedline as the line editor in arf, an R console. R's parser treats
\ras an invalid token, so any CR characters in the input buffer cause parse errors.I currently have to strip CR from the buffer after
read_line()returns, but this is a workaround for what appears to be an unnecessary platform distinction in reedline itself.Why the CRLF insertion is unnecessary
The Windows-specific CRLF was introduced in #399 with the rationale of using the "system newline separator."
However, reedline's own architecture already handles the LF→CRLF conversion at the display layer, making the buffer-level CRLF both redundant and inconsistent with the rest of the codebase:
1. The painting layer already handles CRLF conversion
coerce_crlf()converts bare LF to CRLF right before writing to the terminal.reedline/src/painting/utils.rs
Lines 8 to 33 in 99764ee
This is applied to all
Print()calls inpainter.rs. The buffer is meant to store logical content (LF only), and the display layer adapts it for the terminal.2. All line-counting logic assumes LF only
The rendering code exclusively uses
\nfor line operations:skip_buffer_lines()usesstring.match_indices('\n')andtrim_end_matches('\n')reedline/src/painting/painter.rs
Lines 53 to 54 in 99764ee
estimate_required_lines()uses.lines()(which splits on\n)screen_to_buffer_offset()checksif grapheme == "\n"reedline/src/painting/painter.rs
Line 640 in 99764ee
A
\rin the buffer is invisible to these calculations, which could lead to off-by-one errors in cursor positioning on Windows.3. Previous fix established that CR in the buffer is harmful
#262 explicitly removed CRLF insertion from the hinter logic, noting:
The same reasoning applies to
insert_newline()— it inserts CR into the buffer outside the painting layer.4. Nushell's parser works around this
Nushell's lexer explicitly ignores standalone
\r:https://github.com/nushell/nushell/blob/10a932e0c9e8e8715ccad006594a70fc83a492d3/crates/nu-parser/src/lex.rs#L633-L637
This suggests the CRLF in the buffer is not useful to nushell either — it's simply tolerated.
What this changes
insert_newline()now always inserts\n, removing the#[cfg(target_os = "windows")]branchcoerce_crlf()continues to handle terminal output