MCPcopy Index your code
hub / github.com/nodejs/node / onData

Function onData

lib/internal/readline/emitKeypressEvents.js:46–83  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

44 let timeoutId;
45
46 function onData(input) {
47 if (stream.listenerCount('keypress') > 0) {
48 const string = stream[KEYPRESS_DECODER].write(input);
49 if (string) {
50 clearTimeout(timeoutId);
51
52 // This supports characters of length 2.
53 iface[kSawKeyPress] = charLengthAt(string, 0) === string.length;
54 iface.isCompletionEnabled = false;
55
56 let length = 0;
57 for (const character of new SafeStringIterator(string)) {
58 length += character.length;
59 if (length === string.length) {
60 iface.isCompletionEnabled = true;
61 }
62
63 try {
64 stream[ESCAPE_DECODER].next(character);
65 // Escape letter at the tail position
66 if (length === string.length && character === kEscape) {
67 timeoutId = setTimeout(triggerEscape, escapeCodeTimeout);
68 }
69 } catch (err) {
70 // If the generator throws (it could happen in the `keypress`
71 // event), we need to restart it.
72 stream[ESCAPE_DECODER] = emitKeys(stream);
73 stream[ESCAPE_DECODER].next();
74 throw err;
75 }
76 }
77 }
78 } else {
79 // Nobody's watching anyway
80 stream.removeListener('data', onData);
81 stream.on('newListener', onNewListener);
82 }
83 }
84
85 function onNewListener(event) {
86 if (event === 'keypress') {

Callers

nothing calls this directly

Calls 9

charLengthAtFunction · 0.85
emitKeysFunction · 0.85
listenerCountMethod · 0.80
nextMethod · 0.65
clearTimeoutFunction · 0.50
setTimeoutFunction · 0.50
writeMethod · 0.45
removeListenerMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…