This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/inquirer/lib/utils/events.js
2019-08-11 20:48:02 +02:00

45 lines
1.3 KiB
JavaScript

'use strict';
var rx = require('rx-lite-aggregates');
function normalizeKeypressEvents(value, key) {
return {value: value, key: key || {}};
}
module.exports = function (rl) {
var keypress = rx.Observable.fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
.filter(function (e) {
// Ignore `enter` key. On the readline, we only care about the `line` event.
return e.key.name !== 'enter' && e.key.name !== 'return';
});
return {
line: rx.Observable.fromEvent(rl, 'line'),
keypress: keypress,
normalizedUpKey: keypress.filter(function (e) {
return e.key.name === 'up' || e.key.name === 'k' || (e.key.name === 'p' && e.key.ctrl);
}).share(),
normalizedDownKey: keypress.filter(function (e) {
return e.key.name === 'down' || e.key.name === 'j' || (e.key.name === 'n' && e.key.ctrl);
}).share(),
numberKey: keypress.filter(function (e) {
return e.value && '123456789'.indexOf(e.value) >= 0;
}).map(function (e) {
return Number(e.value);
}).share(),
spaceKey: keypress.filter(function (e) {
return e.key && e.key.name === 'space';
}).share(),
aKey: keypress.filter(function (e) {
return e.key && e.key.name === 'a';
}).share(),
iKey: keypress.filter(function (e) {
return e.key && e.key.name === 'i';
}).share()
};
};