From 68d11424992d3d8fa6263bce5bfb9f8f05d75eab Mon Sep 17 00:00:00 2001 From: Chapman Pendery <35637443+cpendery@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:35:05 -0800 Subject: [PATCH] fix: improper screen clearing results in blank cells (#121) Signed-off-by: Chapman Pendery --- src/ui/ui-root.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ui/ui-root.ts b/src/ui/ui-root.ts index 8fa5fa3..03ab2b7 100644 --- a/src/ui/ui-root.ts +++ b/src/ui/ui-root.ts @@ -24,20 +24,22 @@ export const render = async (shell: Shell) => { writeOutput(ansi.clearTerminal); term.onData((data) => { - const commandState = term.getCommandState(); - if ((commandState.hasOutput || hasActiveSuggestions) && !commandState.persistentOutput) { - if (term.getCursorState().remainingLines < previousSuggestionsRows) { + if (hasActiveSuggestions) { + // Considers when data includes newlines which have shifted the cursor position downwards + const newlines = Math.max((data.match(/\r/g) || []).length, (data.match(/\n/g) || []).length); + const linesOfInterest = MAX_LINES + newlines; + if (term.getCursorState().remainingLines <= previousSuggestionsRows) { writeOutput( - ansi.cursorHide + + data + + ansi.cursorHide + ansi.cursorSavePosition + - ansi.cursorPrevLine.repeat(MAX_LINES) + - term.getCells(MAX_LINES, "above") + + ansi.cursorPrevLine.repeat(linesOfInterest) + + term.getCells(linesOfInterest, "above") + ansi.cursorRestorePosition + - ansi.cursorShow + - data, + ansi.cursorShow, ); } else { - writeOutput(ansi.cursorHide + ansi.cursorSavePosition + eraseLinesBelow(MAX_LINES + 1) + ansi.cursorRestorePosition + ansi.cursorShow + data); + writeOutput(ansi.cursorHide + ansi.cursorSavePosition + eraseLinesBelow(linesOfInterest + 1) + ansi.cursorRestorePosition + ansi.cursorShow + data); } } else { writeOutput(data); @@ -91,7 +93,7 @@ export const render = async (shell: Shell) => { hasActiveSuggestions = true; } else { if (hasActiveSuggestions) { - if (term.getCursorState().remainingLines < previousSuggestionsRows) { + if (term.getCursorState().remainingLines <= previousSuggestionsRows) { writeOutput( ansi.cursorHide + ansi.cursorSavePosition +