Skip to content

Commit

Permalink
fix: improper screen clearing results in blank cells (#121)
Browse files Browse the repository at this point in the history
Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery authored Dec 14, 2023
1 parent 5c35624 commit 68d1142
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/ui/ui-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 +
Expand Down

0 comments on commit 68d1142

Please sign in to comment.