« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js26
1 files changed, 14 insertions, 12 deletions
diff --git a/index.js b/index.js
index b1c4ced..3abbe83 100755
--- a/index.js
+++ b/index.js
@@ -29,12 +29,6 @@ async function main() {
   const interfacer = new CommandLineInterfacer()
   const size = await interfacer.getScreenSize()
 
-  const flushable = new Flushable(process.stdout, true)
-  flushable.resizeScreen(size)
-  flushable.shouldShowCompressionStatistics = process.argv.includes('--show-ansi-stats')
-  flushable.write(ansi.clearScreen())
-  flushable.flush()
-
   const root = new Root(interfacer)
   root.w = size.width
   root.h = size.height
@@ -50,7 +44,12 @@ async function main() {
   root.addChild(appElement)
   root.select(appElement)
 
-  await appElement.setup()
+  const result = await appElement.setup()
+
+  if (result.error) {
+    console.error(result.error)
+    process.exit(1)
+  }
 
   appElement.on('quitRequested', () => {
     process.stdout.write(ansi.cleanCursor())
@@ -66,16 +65,13 @@ async function main() {
   }
 
   if (process.argv[2]) {
-    flushable.write(ansi.moveCursor(0, 0))
-    flushable.write('Opening playlist...')
-    flushable.flush()
+    console.log('Opening playlist...')
 
     let grouplikeText
     try {
       grouplikeText = await readFile(process.argv[2])
     } catch (error) {
-      flushable.write('Error opening the passed file "' + process.argv[2] + '"!')
-      flushable.flush()
+      console.error('Error opening the passed file "' + process.argv[2] + '"!')
       process.exit(1)
     }
 
@@ -94,6 +90,12 @@ async function main() {
 
   root.select(appElement.form)
 
+  const flushable = new Flushable(process.stdout, true)
+  flushable.resizeScreen(size)
+  flushable.shouldShowCompressionStatistics = process.argv.includes('--show-ansi-stats')
+  flushable.write(ansi.clearScreen())
+  flushable.flush()
+
   setInterval(() => {
     root.renderTo(flushable)
     flushable.flush()