« 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.js26
-rw-r--r--todo.txt2
-rw-r--r--ui.js9
3 files changed, 25 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()
diff --git a/todo.txt b/todo.txt
index e190b31..c008d46 100644
--- a/todo.txt
+++ b/todo.txt
@@ -27,3 +27,5 @@ TODO: Pressing enter in the queue seems to not be doing the right thing?
       (Done!)
 
 TODO: iTunes downloader - test this.
+
+TODO: Warn if no mkfifo (means controls won't work).
diff --git a/ui.js b/ui.js
index ac86a47..371958d 100644
--- a/ui.js
+++ b/ui.js
@@ -95,9 +95,18 @@ class AppElement extends FocusElement {
 
   async setup() {
     this.player = await getPlayer()
+
+    if (!this.player) {
+      return {
+        error: "Sorry, it doesn't look like there's an audio player installed on your computer. Can you try installing MPV (https://mpv.io) or SoX?"
+      }
+    }
+
     this.player.on('printStatusLine', data => {
       this.playbackInfoElement.updateProgress(data)
     })
+
+    return true
   }
 
   async shutdown() {