summaryrefslogtreecommitdiff
path: root/lib/repl.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-12-05 14:41:49 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-12-10 00:23:23 +0100
commit6bdf8d106009e4ed0f3c323d0f0874a51acc8e08 (patch)
tree57153227fef5cac26ae147e44bf571eee646feef /lib/repl.js
parent02a0c74861c3107e6a9a1752e91540f8d4c49a76 (diff)
downloadandroid-node-v8-6bdf8d106009e4ed0f3c323d0f0874a51acc8e08.tar.gz
android-node-v8-6bdf8d106009e4ed0f3c323d0f0874a51acc8e08.tar.bz2
android-node-v8-6bdf8d106009e4ed0f3c323d0f0874a51acc8e08.zip
repl: support previews by eager evaluating input
This adds input previews by using the inspectors eager evaluation functionality. It is implemented as additional line that is not counted towards the actual input. In case no colors are supported, it will be visible as comment. Otherwise it's grey. It will be triggered on any line change. It is heavily tested against edge cases and adheres to "dumb" terminals (previews are deactived in that case). PR-URL: https://github.com/nodejs/node/pull/30811 Fixes: https://github.com/nodejs/node/issues/20977 Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'lib/repl.js')
-rw-r--r--lib/repl.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/repl.js b/lib/repl.js
index b6876bb8c6..98b0d2415d 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -98,7 +98,8 @@ const experimentalREPLAwait = require('internal/options').getOptionValue(
);
const {
isRecoverableError,
- kStandaloneREPL
+ kStandaloneREPL,
+ setupPreview,
} = require('internal/repl/utils');
const {
getOwnNonIndexProperties,
@@ -204,6 +205,9 @@ function REPLServer(prompt,
}
}
+ const preview = options.terminal &&
+ (options.preview !== undefined ? !!options.preview : true);
+
this.inputStream = options.input;
this.outputStream = options.output;
this.useColors = !!options.useColors;
@@ -804,9 +808,20 @@ function REPLServer(prompt,
}
});
+ const {
+ clearPreview,
+ showInputPreview
+ } = setupPreview(
+ this,
+ kContextId,
+ kBufferedCommandSymbol,
+ preview
+ );
+
// Wrap readline tty to enable editor mode and pausing.
const ttyWrite = self._ttyWrite.bind(self);
self._ttyWrite = (d, key) => {
+ clearPreview();
key = key || {};
if (paused && !(self.breakEvalOnSigint && key.ctrl && key.name === 'c')) {
pausedBuffer.push(['key', [d, key]]);
@@ -819,6 +834,7 @@ function REPLServer(prompt,
self.clearLine();
}
ttyWrite(d, key);
+ showInputPreview();
return;
}