From 98b2c1faa886a20695343b54bac1b2b6f85b3579 Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 31 May 2018 00:01:05 -0300 Subject: Seek controls --- index.js | 54 ------------------------------------------------------ tui-lib | 2 +- ui.js | 24 ++++++++++++++++++++++-- 3 files changed, 23 insertions(+), 57 deletions(-) diff --git a/index.js b/index.js index 5f592df..6a3c8f8 100644 --- a/index.js +++ b/index.js @@ -15,61 +15,7 @@ process.on('unhandledRejection', error => { process.exit(1) }) -class InternalApp extends EventEmitter { - constructor() { - super() - this.player = null - } - - async setup() { - this.player = await getPlayer() - } - - async startPlaying(arg) { - this.player.playFile(await this.download(arg)) - } - - stopPlaying() { - this.player.kill() - } - - seekAhead(seconds) { - this.player.seekAhead(seconds) - } - - seekBehind(seconds) { - this.player.seekBehind(seconds) - } - - togglePause() { - this.player.togglePause() - } - - download(arg) { - return getDownloaderFor(arg)(arg) - } -} - async function main() { - /* - const internalApp = new InternalApp() - await internalApp.setup() - - await internalApp.startPlaying('http://billwurtz.com/cable-television.mp3') - await new Promise(r => setTimeout(r, 2000)) - internalApp.togglePause() - await new Promise(r => setTimeout(r, 1000)) - internalApp.togglePause() - await new Promise(r => setTimeout(r, 2000)) - internalApp.stopPlaying() - */ - - /* - for (const item of require('./flat.json').items) { - await internalApp.download(item.downloaderArg) - } - */ - const interfacer = new CommandLineInterfacer() const size = await interfacer.getScreenSize() diff --git a/tui-lib b/tui-lib index 581c8db..f267629 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit 581c8db27bc25c74b02a1b29d795c847118c6234 +Subproject commit f2676294c95695e2de3a7fb88eafae76d6827618 diff --git a/ui.js b/ui.js index f293671..68c6d73 100644 --- a/ui.js +++ b/ui.js @@ -70,12 +70,32 @@ class AppElement extends FocusElement { } keyPressed(keyBuf) { - if (keyBuf[0] === 0x03 || keyBuf[0] === 'q'.charCodeAt(0) || keyBuf[0] === 'Q'.charCodeAt(0)) { + if (keyBuf[0] === 0x03 || telc.isCaselessLetter(keyBuf, 'q')) { this.shutdown() return } - super.keyPressed(keyBuf) + if (telc.isRight(keyBuf) || telc.isCaselessLetter(keyBuf, 'l')) { + this.seekAhead(10) + } else if (telc.isLeft(keyBuf) || telc.isCaselessLetter(keyBuf, 'j')) { + this.seekBack(10) + } else if (telc.isCaselessLetter(keyBuf, 'p') || telc.isCaselessLetter(keyBuf, 'k')) { + this.togglePause() + } else { + super.keyPressed(keyBuf) + } + } + + seekAhead(seconds) { + this.player.seekAhead(seconds) + } + + seekBack(seconds) { + this.player.seekBack(seconds) + } + + togglePause() { + this.player.togglePause() } async queueGrouplikeItem(item, play = true) { -- cgit 1.3.0-6-gf8a5