« 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
diff options
context:
space:
mode:
-rw-r--r--util/CommandLineInterfacer.js7
-rw-r--r--util/Flushable.js9
2 files changed, 14 insertions, 2 deletions
diff --git a/util/CommandLineInterfacer.js b/util/CommandLineInterfacer.js
index 743ff5c..d2007fb 100644
--- a/util/CommandLineInterfacer.js
+++ b/util/CommandLineInterfacer.js
@@ -3,17 +3,22 @@ const waitForData = require('./waitForData')
 const ansi = require('./ansi')
 
 module.exports = class CommandLineInterfacer extends EventEmitter {
-  constructor(inStream = process.stdin, outStream = process.stdout) {
+  constructor(inStream = process.stdin, outStream = process.stdout, proc = process) {
     super()
 
     this.inStream = inStream
     this.outStream = outStream
+    this.process = proc
 
     inStream.on('data', buffer => {
       this.emit('inputData', buffer)
     })
 
     inStream.setRawMode(true)
+
+    proc.on('SIGWINCH', async buffer => {
+      this.emit('resize', await this.getScreenSize())
+    })
   }
 
   async getScreenSize() {
diff --git a/util/Flushable.js b/util/Flushable.js
index 6546b7a..318bb52 100644
--- a/util/Flushable.js
+++ b/util/Flushable.js
@@ -16,9 +16,10 @@ module.exports = class Flushable {
     // and ANSI-interpreted compressed size) in the output of flush.
     this.shouldShowCompressionStatistics = false
 
-    // Update these if you plan on using the ANSI compressor!
+    // Use resizeScreen if you plan on using the ANSI compressor!
     this.screenLines = 24
     this.screenCols = 80
+    this.lastFrame = undefined
 
     this.ended = false
     this.paused = false
@@ -27,6 +28,12 @@ module.exports = class Flushable {
     this.chunks = []
   }
 
+  resizeScreen({lines, cols}) {
+    this.screenLines = lines
+    this.screenCols = cols
+    this.lastFrame = undefined
+  }
+
   write(what) {
     this.chunks.push(what)
   }