Skip to content

fix(display): don't emit stray newline on repaint of empty buffer - #123

Merged
maxlandon merged 2 commits into
reeflective:masterfrom
dbactual:fix/empty-prompt-stray-newline
Sep 30, 2026
Merged

maxlandon merged 2 commits into
reeflective:masterfrom
dbactual:fix/empty-prompt-stray-newline

Conversation

@dbactual

Copy link
Copy Markdown
Contributor

Problem

Repainting an empty input line with a zero-width primary prompt emitted a spurious newline — one blank line at startup and one more per repaint of an empty buffer (e.g. backspace on an empty line), causing the display to scroll and drift.

Root cause

In internal/display/refresh.go, displayLine() computed:

wrappedAtRightEdge := e.lineCol == 0 && len(line) > 0

line is the rendered string and always contains ANSI escape codes (selection/background resets, autosuggest styling) even when the input buffer is empty, so len(line) > 0 is always true. When the primary prompt is zero-width, e.lineCol == 0 too, so the forced-wrap newline fired on every repaint of an empty buffer.

Fix

Test the actual buffer length instead of the rendered string's:

wrappedAtRightEdge := e.lineCol == 0 && e.line.Len() > 0

Testing

  • go build ./... passes
  • go test ./internal/display/ passes
  • Manual: with rl.Prompt.Primary(func() string { return "" }), no newline is emitted at startup or on backspace of an empty line; wrapped long lines still print correctly

Verified via a pty harness while integrating v1.3.0.

The wrap heuristic used len(line), but line is the rendered string
and always contains ANSI escape codes, so it was non-empty even when
the input buffer was empty. With a zero-width primary prompt this
caused a spurious newline on every repaint (startup, backspace on
an empty line). Use the actual buffer length instead.
@maxlandon

Copy link
Copy Markdown
Member

Thanks for the fix !

@maxlandon
maxlandon enabled auto-merge September 30, 2026 12:29
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.82%. Comparing base (8c6cfe7) to head (5b14153).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #123   +/-   ##
=======================================
  Coverage   39.82%   39.82%           
=======================================
  Files          60       60           
  Lines        9594     9594           
=======================================
  Hits         3821     3821           
  Misses       5679     5679           
  Partials       94       94           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maxlandon
maxlandon merged commit 60a4fa9 into reeflective:master Sep 30, 2026
11 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.

2 participants