From 3c0cd5c2a98685ab9fd0fdf97a1ac28ceb97dc74 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 13 Jun 2018 21:03:30 -0300 Subject: Error handling stuff --- index.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'index.js') 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() -- cgit 1.3.0-6-gf8a5