source: trip-planner-front/node_modules/inquirer/lib/utils/events.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[6a3a178]1'use strict';
2const { fromEvent } = require('rxjs');
3const { filter, map, share, takeUntil } = require('rxjs/operators');
4
5function normalizeKeypressEvents(value, key) {
6 return { value, key: key || {} };
7}
8
9module.exports = function (rl) {
10 const keypress = fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
11 .pipe(takeUntil(fromEvent(rl, 'close')))
12 // Ignore `enter` key. On the readline, we only care about the `line` event.
13 .pipe(filter(({ key }) => key.name !== 'enter' && key.name !== 'return'));
14
15 return {
16 line: fromEvent(rl, 'line'),
17 keypress,
18
19 normalizedUpKey: keypress.pipe(
20 filter(
21 ({ key }) =>
22 key.name === 'up' || key.name === 'k' || (key.name === 'p' && key.ctrl)
23 ),
24 share()
25 ),
26
27 normalizedDownKey: keypress.pipe(
28 filter(
29 ({ key }) =>
30 key.name === 'down' || key.name === 'j' || (key.name === 'n' && key.ctrl)
31 ),
32 share()
33 ),
34
35 numberKey: keypress.pipe(
36 filter((e) => e.value && '123456789'.indexOf(e.value) >= 0),
37 map((e) => Number(e.value)),
38 share()
39 ),
40
41 spaceKey: keypress.pipe(
42 filter(({ key }) => key && key.name === 'space'),
43 share()
44 ),
45 aKey: keypress.pipe(
46 filter(({ key }) => key && key.name === 'a'),
47 share()
48 ),
49 iKey: keypress.pipe(
50 filter(({ key }) => key && key.name === 'i'),
51 share()
52 ),
53 };
54};
Note: See TracBrowser for help on using the repository browser.