summaryrefslogtreecommitdiff
path: root/lib/readline.js
diff options
context:
space:
mode:
authorRaoof <raoofhb@gmail.com>2018-04-04 00:00:35 +0430
committerJames M Snell <jasnell@gmail.com>2018-10-25 15:19:02 -0700
commitc82920214bc03857061b47fe6bee3b21933eabe8 (patch)
treed78bdf2f3e8fd75037d34bd5473738f51925fb22 /lib/readline.js
parent246a6fc1078ae3ef257169847704dd8db4122095 (diff)
downloadandroid-node-v8-c82920214bc03857061b47fe6bee3b21933eabe8.tar.gz
android-node-v8-c82920214bc03857061b47fe6bee3b21933eabe8.tar.bz2
android-node-v8-c82920214bc03857061b47fe6bee3b21933eabe8.zip
lib: add escapeCodeTimeout as an option to createInterface
PR-URL: https://github.com/nodejs/node/pull/19780 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/readline.js')
-rw-r--r--lib/readline.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/readline.js b/lib/readline.js
index cd8240bc26..4eeefb227c 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -82,6 +82,7 @@ function Interface(input, output, completer, terminal) {
this.isCompletionEnabled = true;
this._sawKeyPress = false;
this._previousKey = null;
+ this.escapeCodeTimeout = ESCAPE_CODE_TIMEOUT;
EventEmitter.call(this);
var historySize;
@@ -99,6 +100,16 @@ function Interface(input, output, completer, terminal) {
if (input.prompt !== undefined) {
prompt = input.prompt;
}
+ if (input.escapeCodeTimeout !== undefined) {
+ if (Number.isFinite(input.escapeCodeTimeout)) {
+ this.escapeCodeTimeout = input.escapeCodeTimeout;
+ } else {
+ throw new ERR_INVALID_OPT_VALUE(
+ 'escapeCodeTimeout',
+ this.escapeCodeTimeout
+ );
+ }
+ }
crlfDelay = input.crlfDelay;
input = input.input;
}
@@ -131,7 +142,6 @@ function Interface(input, output, completer, terminal) {
this.removeHistoryDuplicates = !!removeHistoryDuplicates;
this.crlfDelay = crlfDelay ?
Math.max(kMincrlfDelay, crlfDelay) : kMincrlfDelay;
-
// Check arity, 2 - for async, 1 for sync
if (typeof completer === 'function') {
this.completer = completer.length === 2 ?
@@ -1020,7 +1030,10 @@ function emitKeypressEvents(stream, iface) {
stream[ESCAPE_DECODER].next(r[i]);
// Escape letter at the tail position
if (r[i] === kEscape && i + 1 === r.length) {
- timeoutId = setTimeout(escapeCodeTimeout, ESCAPE_CODE_TIMEOUT);
+ timeoutId = setTimeout(
+ escapeCodeTimeout,
+ iface ? iface.escapeCodeTimeout : ESCAPE_CODE_TIMEOUT
+ );
}
} catch (err) {
// if the generator throws (it could happen in the `keypress`