Browse Source

readline: emit key info unconditionally

Currently, 'keypress' events include the sequence and key info
for named keys, but only the sequence for unnamed keys. This
commit causes the key info to be included in both cases.

PR-URL: https://github.com/nodejs/node/pull/6024
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
process-exit-stdio-flushing
cjihrig 9 years ago
parent
commit
0a62f929da
  1. 5
      lib/internal/readline.js
  2. 2
      test/parallel/test-readline-keys.js

5
lib/internal/readline.js

@ -384,9 +384,8 @@ function* emitKeys(stream) {
stream.emit('keypress', escaped ? undefined : s, key); stream.emit('keypress', escaped ? undefined : s, key);
} else if (s.length === 1) { } else if (s.length === 1) {
/* Single unnamed character, e.g. "." */ /* Single unnamed character, e.g. "." */
stream.emit('keypress', s); stream.emit('keypress', s, key);
} else {
/* Unrecognized or broken escape sequence, don't emit anything */
} }
/* Unrecognized or broken escape sequence, don't emit anything */
} }
} }

2
test/parallel/test-readline-keys.js

@ -48,7 +48,7 @@ function addTest(sequences, expectedKeys) {
addTest('io.JS', [ addTest('io.JS', [
{ name: 'i', sequence: 'i' }, { name: 'i', sequence: 'i' },
{ name: 'o', sequence: 'o' }, { name: 'o', sequence: 'o' },
undefined, // emitted as `emit('keypress', '.', undefined)` { name: undefined, sequence: '.' },
{ name: 'j', sequence: 'J', shift: true }, { name: 'j', sequence: 'J', shift: true },
{ name: 's', sequence: 'S', shift: true }, { name: 's', sequence: 'S', shift: true },
]); ]);

Loading…
Cancel
Save