diff options
author | Florrie <towerofnix@gmail.com> | 2017-12-10 00:20:17 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2017-12-10 00:20:17 -0400 |
commit | a0c864e531cc793855f0d3462d9f9ef2aca7affa (patch) | |
tree | 98d08b0d53db7426beb186f5bd4517195257d4a1 | |
parent | 1de4c9c10530eb6efbb9af06d5a2cf881ccd85af (diff) |
Add compression statistic monitor to Flushable
-rw-r--r-- | util/Flushable.js | 22 |
1 files 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 } |