Works as an event stream now!

This commit is contained in:
Eddie Antonio Santos 2019-04-11 16:17:54 -06:00
parent abe0ba754a
commit 8f7305c77e
No known key found for this signature in database
GPG key ID: DD411EA4D9509D87
4 changed files with 38 additions and 8 deletions

View file

@ -0,0 +1 @@
node_modules/

View file

@ -90,14 +90,27 @@ function main() {
* shift: false } ]
*
*/
stream.on('keypress', function (char, keypress) {
console.log({char, keypress});
if (keypress.sequence === '\u0003' || keypress.sequence === '\u0004') {
process.exit(0);
}
});
return;
function keypressOf(stream) {
return new EventIterator(
(push, stop, fail) => {
stream.on('keypress', (char, keypress) => push([char, keypress]));
stream.on('close', stop);
stream.on('error', fail);
}
);
}
async function derp() {
for await (let [char, keypress] of keypressOf(stream)) {
console.log({char, keypress});
if (keypress.sequence === '\u0003' || keypress.sequence === '\u0004') {
process.exit(0);
}
}
}
return derp().catch(_ => process.exit(127));
asyncMain()
.then(_ => process.exit(0))

View file

@ -0,0 +1,13 @@
{
"name": "lmlayer-cli",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"event-iterator": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/event-iterator/-/event-iterator-1.2.0.tgz",
"integrity": "sha512-Daq7YUl0Mv1i4QEgzGQlz0jrx7hUFNyLGbiF+Ap7NCMCjDLCCnolyj6s0TAc6HmrBziO5rNVHsPwGMp7KdRPvw=="
}
}
}

View file

@ -7,5 +7,8 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Eddie Antonio Santos <Eddie.Santos@nrc-cnrc.gc.ca>",
"license": "MIT"
"license": "MIT",
"dependencies": {
"event-iterator": "^1.2.0"
}
}