« 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
path: root/util/ansi.js
diff options
context:
space:
mode:
Diffstat (limited to 'util/ansi.js')
-rw-r--r--util/ansi.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/util/ansi.js b/util/ansi.js
index c786db5..ac511ed 100644
--- a/util/ansi.js
+++ b/util/ansi.js
@@ -182,7 +182,8 @@ const ansi = {
 
   interpret(text, scrRows, scrCols, {
     oldChars = null, oldLastChar = null,
-    oldCursorRow = 0, oldCursorCol = 0, oldShowCursor = true
+    oldScrRows = null, oldScrCols = null,
+    oldCursorRow = 1, oldCursorCol = 1, oldShowCursor = true
   } = {}) {
     // Interprets the given ansi code, more or less.
 
@@ -193,9 +194,17 @@ const ansi = {
 
     const chars = new Array(scrRows * scrCols).fill(blank)
 
-    let showCursor = true
-    let cursorRow = 1
-    let cursorCol = 1
+    if (oldChars) {
+      for (let row = 0; row < scrRows && row < oldScrRows; row++) {
+        for (let col = 0; col < scrCols && col < oldScrCols; col++) {
+          chars[row * scrCols + col] = oldChars[row * oldScrCols + col]
+        }
+      }
+    }
+
+    let showCursor = oldShowCursor
+    let cursorRow = oldCursorRow
+    let cursorCol = oldCursorCol
     let attributes = []
 
     for (let charI = 0; charI < text.length; charI++) {
@@ -475,10 +484,12 @@ const ansi = {
 
     return {
       oldChars: newChars.slice(),
+      oldLastChar: Object.assign({}, lastChar),
+      oldScrRows: scrRows,
+      oldScrCols: scrCols,
       oldCursorRow: cursorRow,
       oldCursorCol: cursorCol,
       oldShowCursor: showCursor,
-      oldLastChar: Object.assign({}, lastChar),
       screen: result.join('')
     }
   }