mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-13 11:07:42 +00:00
Works as an event stream now!
This commit is contained in:
parent
abe0ba754a
commit
8f7305c77e
4 changed files with 38 additions and 8 deletions
1
common/test/predictive-text/.gitignore
vendored
Normal file
1
common/test/predictive-text/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
node_modules/
|
||||
|
|
@ -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))
|
||||
|
|
|
|||
13
common/test/predictive-text/package-lock.json
generated
Normal file
13
common/test/predictive-text/package-lock.json
generated
Normal 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=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue