« get me outta code hell

Error handling stuff - 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:
authorFlorrie <towerofnix@gmail.com>2018-06-13 21:03:30 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-13 21:03:30 -0300
commit3c0cd5c2a98685ab9fd0fdf97a1ac28ceb97dc74 (patch)
tree564dfa43da134f10cfaae9405a5152e3316ba51d /index.js
parent4de13b1d3e1cff28e331607b262513a9583aa08a (diff)
Error handling stuff
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()