« get me outta code hell

Better ANSI-interpret debug messages - 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>2018-05-30 10:22:30 -0300
committerFlorrie <towerofnix@gmail.com>2018-05-30 10:22:32 -0300
commit581c8db27bc25c74b02a1b29d795c847118c6234 (patch)
tree8596b34ce05cc8f8ad6715bb88ad7e47f339f6ba
parent7192b51deac9df93bc9a43ec7765b8a5a8eddc82 (diff)
Better ANSI-interpret debug messages
* Show the number of KB saved
* Make the percent-saved a little more precise
* Don't update the debug message if absolutely nothing changed on the
  screen (although, it's still saving however much data it would have
  taken to render the entire screen!!)
* Just draw a bar across the whole screen, instead of a few extra "   "
  characters - technically this adds a whole bunch of data itself but
  it's assumed that you aren't on limited data if you're debugging how
  much data the interpreter saves
-rw-r--r--util/Flushable.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/util/Flushable.js b/util/Flushable.js
index c852421..6546b7a 100644
--- a/util/Flushable.js
+++ b/util/Flushable.js
@@ -1,4 +1,5 @@
 const ansi = require('./ansi')
+const unic = require('./unichars')
 
 module.exports = class Flushable {
   // A writable that can be used to collect chunks of data before writing
@@ -95,11 +96,17 @@ module.exports = class Flushable {
     this.lastFrame = output
 
     if (this.shouldShowCompressionStatistics) {
-      const pcSaved = Math.round(100 - (100 / toWrite.length * screen.length))
-      screen += (
-        '\x1b[H\x1b[0m(ANSI-interpret: ' +
-        `${toWrite.length} -> ${screen.length} ${pcSaved}% saved)  `
-      )
+      let msg = this.lastInterpretMessage
+      if (screen.length > 0 || !this.lastInterpretMessage) {
+        const pcSaved = Math.round(1000 - (1000 / toWrite.length * screen.length)) / 10
+        const kbSaved = Math.round((toWrite.length - screen.length) / 100) / 10
+        msg = this.lastInterpretMessage = (
+          '(ANSI-interpret: ' +
+          `${toWrite.length} -> ${screen.length} ${pcSaved}% / ${kbSaved} KB saved)`
+        )
+      }
+      screen += '\x1b[H\x1b[0m'
+      screen += msg + unic.BOX_H_DOUBLE.repeat(this.screenCols - msg.length)
       this.lastFrame.oldLastChar.attributes = []
     }