Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

events.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. var { fromEvent } = require('rxjs');
  3. var { filter, map, share } = require('rxjs/operators');
  4. function normalizeKeypressEvents(value, key) {
  5. return { value: value, key: key || {} };
  6. }
  7. module.exports = function(rl) {
  8. var keypress = fromEvent(rl.input, 'keypress', normalizeKeypressEvents)
  9. // Ignore `enter` key. On the readline, we only care about the `line` event.
  10. .pipe(filter(({ key }) => key.name !== 'enter' && key.name !== 'return'));
  11. return {
  12. line: fromEvent(rl, 'line'),
  13. keypress: keypress,
  14. normalizedUpKey: keypress.pipe(
  15. filter(
  16. ({ key }) =>
  17. key.name === 'up' || key.name === 'k' || (key.name === 'p' && key.ctrl)
  18. ),
  19. share()
  20. ),
  21. normalizedDownKey: keypress.pipe(
  22. filter(
  23. ({ key }) =>
  24. key.name === 'down' || key.name === 'j' || (key.name === 'n' && key.ctrl)
  25. ),
  26. share()
  27. ),
  28. numberKey: keypress.pipe(
  29. filter(e => e.value && '123456789'.indexOf(e.value) >= 0),
  30. map(e => Number(e.value)),
  31. share()
  32. ),
  33. spaceKey: keypress.pipe(
  34. filter(({ key }) => key && key.name === 'space'),
  35. share()
  36. ),
  37. aKey: keypress.pipe(
  38. filter(({ key }) => key && key.name === 'a'),
  39. share()
  40. ),
  41. iKey: keypress.pipe(
  42. filter(({ key }) => key && key.name === 'i'),
  43. share()
  44. )
  45. };
  46. };