« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xindex.js23
1 files 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()