Skip to content

fix(display): fix clear-below logic at terminal bottom#95

Open
liamg wants to merge 2 commits intoreeflective:masterfrom
liamg:fix/refresh-clear-at-bottom
Open

fix(display): fix clear-below logic at terminal bottom#95
liamg wants to merge 2 commits intoreeflective:masterfrom
liamg:fix/refresh-clear-at-bottom

Conversation

@liamg
Copy link
Contributor

@liamg liamg commented Feb 22, 2026

Summary

  • Fix ClearScreenBelow erasing the prompt/input line when the cursor is on the last terminal row
  • Fix multiline prompt rendering twice (❯ ❯) and terminal lockup when the prompt is near the bottom of the screen

Problem

MoveCursorDown (CUD / \x1b[1B) is a no-op on the last terminal line. The original Refresh() code used CUD to move below the input before calling ClearScreenBelow, which meant the clear would erase the prompt itself when at the bottom.

The initial fix (replacing CUD with \r\n) introduced a regression: \r\n unconditionally scrolls the terminal when on the last row, displacing the prompt upward on every refresh cycle. This caused the last line of multiline prompts to render twice and could lead to the terminal appearing to lock up (likely due to corrupted cursor position state).

Fix

Skip the clear-below entirely when the input line is already at the bottom of the terminal — there's nothing below to clear in that case. When not at the bottom, use the original CUD approach which works correctly.

Also simplify renderHelpers since Refresh() now handles the clear-below before calling it.

I've tested this on a few terminals and it seems to work well.

MoveCursorDown (CUD / \x1b[1B) is a no-op when the cursor is on the
last line of the terminal. This caused ClearScreenBelow to erase the
prompt/input line instead of clearing below it, making the prompt
invisible whenever the input line was at the bottom of the screen.

Replace MoveCursorDown(1) with NewlineReturn ("\r\n") in Refresh and
renderHelpers. Unlike CUD, \r\n scrolls the terminal when at the
bottom, ensuring the cursor always advances to a new line before
clearing.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.54%. Comparing base (0637db4) to head (f79650a).
⚠️ Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
internal/display/refresh.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #95      +/-   ##
==========================================
- Coverage   33.03%   32.54%   -0.50%     
==========================================
  Files          57       58       +1     
  Lines        9109     9207      +98     
==========================================
- Hits         3009     2996      -13     
- Misses       6062     6173     +111     
  Partials       38       38              

☔ View full report in Codecov by Sentry.
📢 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
Copy link
Member

Hello !

Thanks for this.
Can you tell me if the behavior in Vim mode + multi-line input lines is still working correctly ?
Thanks a lot

@liamg
Copy link
Contributor Author

liamg commented Feb 23, 2026

@maxlandon Yep, that's the main way I'm using it atm and it seems ok 👍

@maxlandon
Copy link
Member

Okay give me a few days and I will merge it. Very very busy at the moment...

@liamg
Copy link
Contributor Author

liamg commented Feb 25, 2026

No rush at all, thank you!

@liamg liamg marked this pull request as draft March 11, 2026 20:38
@liamg liamg changed the title fix(display): use newline instead of CUD to scroll at terminal bottom fix(display): fix clear-below logic at terminal bottom Mar 11, 2026
@liamg liamg marked this pull request as ready for review March 11, 2026 20:45
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