From a48c6bbbbcca48ddc0bade66b33781e13f80213d Mon Sep 17 00:00:00 2001 From: liam4 Date: Sun, 11 Jun 2017 10:04:09 -0300 Subject: Beginnings of keyboard controls --- src/http-music.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/http-music.js') diff --git a/src/http-music.js b/src/http-music.js index fee1b79..3d7e217 100755 --- a/src/http-music.js +++ b/src/http-music.js @@ -239,7 +239,28 @@ setupDefaultPlaylist('./playlist.json') return } - return loopPlay(picker, downloader, playOpts) + const play = loopPlay(picker, downloader, playOpts) + + // We're looking to gather standard input one keystroke at a time. + process.stdin.setRawMode(true) + + process.stdin.on('data', data => { + if (Buffer.from('s').equals(data)) { + play.skip() + } + + if ( + Buffer.from('q').equals(data) || + Buffer.from([0x03]).equals(data) || // ^C + Buffer.from([0x04]).equals(data) // ^D + ) { + play.kill() + process.stdout.write('\n') + process.exit(0) + } + }) + + return play.promise } else { return activePlaylist } -- cgit 1.3.0-6-gf8a5