« get me outta code hell

Make ansi interpreter work with selective control sequences - 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:
authorFlorrie <towerofnix@gmail.com>2017-12-09 23:45:05 -0400
committerFlorrie <towerofnix@gmail.com>2017-12-09 23:45:05 -0400
commit1de4c9c10530eb6efbb9af06d5a2cf881ccd85af (patch)
treec0c19b47806efa83d5fe8853bd782f580bb0e217
parent21d1a6724eadcf91a616beb06ad763e7e5fafcdc (diff)
Make ansi interpreter work with selective control sequences
-rw-r--r--util/ansi.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/util/ansi.js b/util/ansi.js
index 564fdf8..f3f4cbe 100644
--- a/util/ansi.js
+++ b/util/ansi.js
@@ -129,6 +129,7 @@ const ansi = {
 
     const chars = new Array(scrRows * scrCols).fill(blank)
 
+    let showCursor = true
     let cursorRow = 1
     let cursorCol = 1
     const attributes = []
@@ -144,6 +145,12 @@ const ansi = {
 
         charI++
 
+        // Selective control sequences (look them up) - we can just skip the
+        // question mark.
+        if (text[charI] === '?') {
+          charI++
+        }
+
         const args = []
         let val = ''
         while (isDigit(text[charI])) {
@@ -165,6 +172,13 @@ const ansi = {
           cursorCol = args[1]
         }
 
+        // SM - Set Mode
+        if (text[charI] === 'h') {
+          if (args[0] === '25') {
+            showCursor = true
+          }
+        }
+
         // ED - Erase Display (clearScreen)
         if (text[charI] === 'J') {
           // ESC[2J - erase whole display
@@ -190,6 +204,13 @@ const ansi = {
           }
         }
 
+        // RM - Reset Mode
+        if (text[charI] === 'l') {
+          if (args[0] === '25') {
+            showCursor = false
+          }
+        }
+
         // SGR - Select Graphic Rendition
         if (text[charI] === 'm') {
           for (let arg of args) {