Skip to content

fix(terminals): normalize bare LF to CRLF in piped readonly output#104

Merged
antfu merged 1 commit into
mainfrom
fix/terminals-pipe-crlf
Jul 16, 2026
Merged

fix(terminals): normalize bare LF to CRLF in piped readonly output#104
antfu merged 1 commit into
mainfrom
fix/terminals-pipe-crlf

Conversation

@antfubot

Copy link
Copy Markdown
Collaborator

Problem

Readonly terminal sessions render output as a staircase — each new line starts at the column where the previous line ended instead of at column 0.

Cause

Readonly sessions spawn through `spawnPipe` (a `child_process` with piped stdio), not a PTY. A piped child has no controlling TTY, so the kernel's `ONLCR` line discipline never runs and its stdout/stderr arrive with bare `\n` line endings. xterm.js only returns the cursor to column 0 on `\r`, so a bare `\n` drops the cursor down a row at its current column. Interactive PTY sessions are unaffected because the kernel translates `\n`→`\r\n` for them.

Fix

`spawnPipe` now normalizes its output before forwarding, mimicking `ONLCR`:

  • Translates lone `\n` → `\r\n`.
  • Leaves an existing `\r\n` untouched.
  • Tracks a `\r` left dangling at a chunk boundary so a `\r\n` split across two data chunks isn't doubled into `\r\r\n`.

Only the pipe backend is touched, so PTY fidelity (progress bars, bare `\r`, TUIs) is preserved.

Verification

Added a test asserting `a\nb\r\nc` renders as `a\r\nb\r\nc` with no doubled `\r\r\n`. All terminals tests pass; lint and typecheck clean.

This PR was created with the help of an agent.

A piped child process has no controlling TTY, so its stdout/stderr carry
bare \n line endings that xterm renders as a staircase (no cursor return
to column 0). Translate lone \n to \r\n in spawnPipe, mirroring the
kernel's ONLCR translation, while leaving existing \r\n untouched.
@netlify

netlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit 0d455a9
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a5896c9638cd70008b59796
😎 Deploy Preview https://deploy-preview-104--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@antfu
antfu merged commit b9a9baa into main Jul 16, 2026
11 of 12 checks passed
@antfu
antfu deleted the fix/terminals-pipe-crlf branch July 16, 2026 08:31
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.

2 participants