From 581c8db27bc25c74b02a1b29d795c847118c6234 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 30 May 2018 10:22:30 -0300 Subject: 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 --- util/Flushable.js | 17 ++++++++++++----- 1 file 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 = [] } -- cgit 1.3.0-6-gf8a5