« get me outta code hell

fix ansi.interpret crashing on cursor visibility change - tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
path: root/util/ansi.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-16 17:23:31 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-16 17:24:25 -0300
commited53efd56caec13fbe58aad5a431296b1ebd6e4d (patch)
treec001c9e88ec3005ce146c1d849167ecc4ab07194 /util/ansi.js
parent34b7ff22766bae0e4b1b3121bd63d037c27285c7 (diff)
fix ansi.interpret crashing on cursor visibility change
Diffstat (limited to 'util/ansi.js')
-rw-r--r--util/ansi.js20
1 files changed, 11 insertions, 9 deletions
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('')
   }
 }