Skip to content

Commit 3de9bc9

Browse files
committed
readline: document emitKeypressEvents()
This commit adds documentation to the already publicly available readline.emitKeypressEvents() method. PR-URL: #6024 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent b85a50b commit 3de9bc9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

doc/api/readline.markdown

+5
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ a `'resize'` event on the `output` if/when the columns ever change
354354

355355
Move cursor to the specified position in a given TTY stream.
356356

357+
## readline.emitKeypressEvents(stream)
358+
359+
Causes `stream` to begin emitting `'keypress'` events corresponding to its
360+
input.
361+
357362
## readline.moveCursor(stream, dx, dy)
358363

359364
Move cursor relative to it's current position in a given TTY stream.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
// emitKeypressEvents is thoroughly tested in test-readline-keys.js.
3+
// However, that test calls it implicitly. This is just a quick sanity check
4+
// to verify that it works when called explicitly.
5+
6+
require('../common');
7+
const assert = require('assert');
8+
const readline = require('readline');
9+
const PassThrough = require('stream').PassThrough;
10+
const stream = new PassThrough();
11+
const sequence = [];
12+
const keys = [];
13+
14+
readline.emitKeypressEvents(stream);
15+
16+
stream.on('keypress', (s, k) => {
17+
sequence.push(s);
18+
keys.push(k);
19+
});
20+
21+
stream.write('foo');
22+
23+
process.on('exit', () => {
24+
assert.deepStrictEqual(sequence, ['f', 'o', 'o']);
25+
assert.deepStrictEqual(keys, [
26+
{ sequence: 'f', name: 'f', ctrl: false, meta: false, shift: false },
27+
{ sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false },
28+
{ sequence: 'o', name: 'o', ctrl: false, meta: false, shift: false }
29+
]);
30+
});

0 commit comments

Comments
 (0)