From ed53efd56caec13fbe58aad5a431296b1ebd6e4d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 16 May 2024 17:23:31 -0300 Subject: fix ansi.interpret crashing on cursor visibility change --- util/ansi.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'util/ansi.js') diff --git a/util/ansi.js b/util/ansi.js index 4e8abb0..997e824 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -216,7 +216,7 @@ export function isANSICommand(buffer, code = null) { export function interpret(text, scrRows, scrCols, { oldChars = null, oldLastChar = null, oldScrRows = null, oldScrCols = null, - oldCursorRow = 1, oldCursorCol = 1, oldShowCursor = true + oldCursorRow = 1, oldCursorCol = 1, oldShowingCursor = true } = {}) { // Interprets the given ansi code, more or less. @@ -235,7 +235,7 @@ export function interpret(text, scrRows, scrCols, { } } - let showCursor = oldShowCursor + let showingCursor = oldShowingCursor let cursorRow = oldCursorRow let cursorCol = oldCursorCol let attributes = [] @@ -282,7 +282,7 @@ export function interpret(text, scrRows, scrCols, { // SM - Set Mode if (text[charI] === 'h') { if (args[0] === '25') { - showCursor = true + showingCursor = true } } @@ -316,7 +316,7 @@ export function interpret(text, scrRows, scrCols, { // RM - Reset Mode if (text[charI] === 'l') { if (args[0] === '25') { - showCursor = false + showingCursor = false } } @@ -509,10 +509,12 @@ export function interpret(text, scrRows, scrCols, { // If the cursor is visible and wasn't before, or vice versa, we need to // show that: - if (showCursor && !oldShowCursor) { - result.push(showCursor()) - } else if (!showCursor && oldShowCursor) { - result.push(hideCursor()) + if (showingCursor !== oldShowingCursor) { + if (showingCursor) { + result.push(showCursor()) + } else { + result.push(hideCursor()) + } } return { @@ -522,7 +524,7 @@ export function interpret(text, scrRows, scrCols, { oldScrCols: scrCols, oldCursorRow: cursorRow, oldCursorCol: cursorCol, - oldShowCursor: showCursor, + oldShowingCursor: showingCursor, screen: result.join('') } } -- cgit 1.3.0-6-gf8a5