« 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
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ansi.js12
1 files changed, 5 insertions, 7 deletions
diff --git a/util/ansi.js b/util/ansi.js
index 94de1a3..04722c0 100644
--- a/util/ansi.js
+++ b/util/ansi.js
@@ -134,7 +134,7 @@ const ansi = {
     let showCursor = true
     let cursorRow = 1
     let cursorCol = 1
-    const attributes = []
+    let attributes = []
 
     for (let charI = 0; charI < text.length; charI++) {
       const cursorIndex = (cursorRow - 1) * scrCols + (cursorCol - 1)
@@ -219,13 +219,14 @@ const ansi = {
         if (text[charI] === 'm') {
           const removeAttribute = attr => {
             if (attributes.includes(attr)) {
+              attributes = attributes.slice()
               attributes.splice(attributes.indexOf(attr), 1)
             }
           }
 
           for (const arg of args) {
             if (arg === '0') {
-              attributes.splice(0, attributes.length)
+              attributes = []
             } else if (arg === '22') { // Neither bold nor faint
               removeAttribute('1')
               removeAttribute('2')
@@ -251,7 +252,7 @@ const ansi = {
                 removeAttribute('4' + i)
               }
             } else {
-              attributes.push(arg)
+              attributes = attributes.concat([arg])
             }
           }
         }
@@ -260,8 +261,7 @@ const ansi = {
       }
 
       chars[cursorIndex] = {
-        char: text[charI],
-        attributes: attributes.slice()
+        char: text[charI], attributes
       }
 
       cursorCol++
@@ -289,8 +289,6 @@ const ansi = {
       differences.push(newChars.slice())
     } else {
       const charsEqual = (oldChar, newChar) => {
-        // TODO: Check attributes.
-
         if (oldChar.char !== newChar.char) {
           return false
         }