From a0c864e531cc793855f0d3462d9f9ef2aca7affa Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 10 Dec 2017 00:20:17 -0400 Subject: Add compression statistic monitor to Flushable --- util/Flushable.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/util/Flushable.js b/util/Flushable.js index b031677..2248fec 100644 --- a/util/Flushable.js +++ b/util/Flushable.js @@ -11,6 +11,10 @@ module.exports = class Flushable { // doesn't *quite* work but should drastically decrease write size? this.shouldCompress = shouldCompress + // Whether or not to show compression statistics (original written size + // and ANSI-interpreted compressed size) in the output of flush. + this.shouldShowCompressionStatistics = false + // Update these if you plan on using the ANSI compressor! this.screenLines = 24 this.screenCols = 80 @@ -82,15 +86,15 @@ module.exports = class Flushable { compress(toWrite) { // TODO: customize screen size - const screen = ansi.interpret(toWrite, this.screenLines, this.screenCols) - - /* - const pcSaved = Math.round(100 - (100 / toWrite.length * screen.length)) - console.log( - '\x1b[1A' + - `${toWrite.length} - ${screen.length} ${pcSaved}% saved ` - ) - */ + let screen = ansi.interpret(toWrite, this.screenLines, this.screenCols) + + if (this.shouldShowCompressionStatistics) { + const pcSaved = Math.round(100 - (100 / toWrite.length * screen.length)) + screen += ( + '\x1b[1A (ANSI-interpret: ' + + `${toWrite.length} -> ${screen.length} ${pcSaved}% saved)` + ) + } return screen } -- cgit 1.3.0-6-gf8a5