Skip to content

Skip CRLF normalization on alt screen#306

Merged
emil-e merged 1 commit into
dakra:mainfrom
devsunb:skip-crlf-normalization-on-alt-screen
May 21, 2026
Merged

Skip CRLF normalization on alt screen#306
emil-e merged 1 commit into
dakra:mainfrom
devsunb:skip-crlf-normalization-on-alt-screen

Conversation

@devsunb
Copy link
Copy Markdown
Contributor

@devsunb devsunb commented May 21, 2026

Summary

Skip bare-LF -> CRLF normalization while the terminal is on the alternate screen.

Why

Emacs PTYs lack ONLCR, so the module inserts \r before each bare \n - correct for line-oriented output on the primary screen. But alt-screen apps (tmux, vim, less) emit VT-correct LF (cursor down, column preserved); normalizing those to \r\n corrupts their layout.

Fix

Skip the conversion when the active screen is the alternate one:

if (term.terminal.screens.active_key == .alternate) {
    term.vtWrite(raw);
    ...
}

Detection via screens.active_key covers all three alt-screen entry modes (DECSET 47 / 1047 / 1049) uniformly. last_input_was_cr is still maintained so a CRLF pair split across writes isn't mis-normalized into \r\r\n.

Demo

Before

before.mp4

After

after.mp4

Apps that use the alternate screen (tmux, vim, less) emit VT-correct
sequences where a bare `\n` means LF (cursor down, column preserved).
Normalizing those to `\r\n` corrupts their layout.

Skip the bare-LF -> CRLF conversion whenever the active screen is the
alternate. Detection uses `terminal.screens.active_key == .alternate`
so all three alt-screen entry modes (DECSET 47 / 1047 / 1049) are
covered uniformly.
@dakra
Copy link
Copy Markdown
Owner

dakra commented May 21, 2026

@emil-e you have a quick look as well but lgtm

@emil-e emil-e merged commit 3a3aefb into dakra:main May 21, 2026
20 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.

3 participants