« get me outta code hell

Show/hide cursor in ANSI interpreter - 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
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-12-10 11:17:00 -0400
committerFlorrie <towerofnix@gmail.com>2017-12-10 11:17:00 -0400
commitb821577ad665520ecc392cf3c6be7f9bc9545b0e (patch)
treeae9f5330892cc6d9969f738801c9ffa644d28472 /util
parentce20598ca90b922592e1ddf38eb8f218cc9daa73 (diff)
Show/hide cursor in ANSI interpreter
Diffstat (limited to 'util')
-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('')
     }