From 4207cf479f91d4cad9cad5583d069efc8fd24c31 Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 8 Oct 2018 11:36:47 -0300 Subject: Less-buggy resize detection Moved .on('resize') to be after the flushable is actually created, so we don't get an error (flushable is not defined) when resizing before the flushable has been created. Also checked for size only immediately before we actually display, so that the size is accurate right away. --- index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 3d7adf8..9682e95 100755 --- a/index.js +++ b/index.js @@ -28,18 +28,8 @@ process.on('unhandledRejection', error => { async function main() { const interfacer = new CommandLineInterfacer() - const size = await interfacer.getScreenSize() const root = new Root(interfacer) - root.w = size.width - root.h = size.height - - interfacer.on('resize', newSize => { - root.w = newSize.width - root.h = newSize.height - flushable.resizeScreen(newSize) - root.fixAllLayout() - }) const appElement = new AppElement() root.addChild(appElement) @@ -71,12 +61,25 @@ async function main() { root.select(appElement) + // Check size, now that we're about to display. + const size = await interfacer.getScreenSize() + root.w = size.width + root.h = size.height + root.fixAllLayout() + const flushable = new Flushable(process.stdout, true) flushable.resizeScreen(size) flushable.shouldShowCompressionStatistics = process.argv.includes('--show-ansi-stats') flushable.write(ansi.clearScreen()) flushable.flush() + interfacer.on('resize', newSize => { + root.w = newSize.width + root.h = newSize.height + flushable.resizeScreen(newSize) + root.fixAllLayout() + }) + setInterval(() => { root.renderTo(flushable) flushable.flush() -- cgit 1.3.0-6-gf8a5