« get me outta code hell

tui-lib - Pure Node.js library for making visual command-line programs (ala vim, ncdu)
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--util/ansi.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/util/ansi.js b/util/ansi.js
index a303cd6..9645f0d 100644
--- a/util/ansi.js
+++ b/util/ansi.js
@@ -121,7 +121,7 @@ const ansi = {
 
   interpret(text, scrRows, scrCols, {
     oldChars = null, oldLastChar = null,
-    oldCursorRow = 0, oldCursorCol = 0
+    oldCursorRow = 0, oldCursorCol = 0, oldShowCursor = true
   } = {}) {
     // Interprets the given ansi code, more or less.
 
@@ -406,10 +406,19 @@ const ansi = {
       result.push(ansi.moveCursor(cursorRow, cursorCol))
     }
 
+    // If the cursor is visible and wasn't before, or vice versa, we need to
+    // show that:
+    if (showCursor && !oldShowCursor) {
+      result.push(ansi.showCursor())
+    } else if (!showCursor && oldShowCursor) {
+      result.push(ansi.hideCursor())
+    }
+
     return {
       oldChars: newChars.slice(),
       oldCursorRow: cursorRow,
       oldCursorCol: cursorCol,
+      oldShowCursor: showCursor,
       oldLastChar: Object.assign({}, lastChar),
       screen: result.join('')
     }