From df43754fe1bf70042ae364f2365b42271468f102 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 21 Feb 2019 15:33:46 +0100 Subject: [PATCH] repl: hide editor mode if not used in a terminal The editor mode is only useable when used as terminal. Hide it from the user in case the repl terminal option is not set. PR-URL: https://github.com/nodejs/node/pull/26240 Reviewed-By: Anna Henningsen Reviewed-By: Anto Aravinth Reviewed-By: Roman Reiss Reviewed-By: Jeremiah Senkpiel --- lib/repl.js | 20 ++++++++++---------- test/parallel/test-repl-save-load.js | 2 +- test/parallel/test-repl.js | 1 - 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 3d0c367918256a..5db94641a3c3d1 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1479,16 +1479,16 @@ function defineDefaultCommands(repl) { this.displayPrompt(); } }); - - repl.defineCommand('editor', { - help: 'Enter editor mode', - action() { - if (!this.terminal) return; - _turnOnEditorMode(this); - this.outputStream.write( - '// Entering editor mode (^D to finish, ^C to cancel)\n'); - } - }); + if (repl.terminal) { + repl.defineCommand('editor', { + help: 'Enter editor mode', + action() { + _turnOnEditorMode(this); + this.outputStream.write( + '// Entering editor mode (^D to finish, ^C to cancel)\n'); + } + }); + } } function regexpEscape(s) { diff --git a/test/parallel/test-repl-save-load.js b/test/parallel/test-repl-save-load.js index 7d6f28548f7056..eff05a39203acd 100644 --- a/test/parallel/test-repl-save-load.js +++ b/test/parallel/test-repl-save-load.js @@ -61,7 +61,7 @@ assert.strictEqual(fs.readFileSync(saveFileName, 'utf8'), '}' ]; const putIn = new ArrayStream(); - const replServer = repl.start('', putIn); + const replServer = repl.start({ terminal: true, stream: putIn }); putIn.run(['.editor']); putIn.run(cmds); diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 6e3bca24e25932..bcaa39f6aa8215 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -439,7 +439,6 @@ const errorTests = [ expect: [ /\.break/, /\.clear/, - /\.editor/, /\.exit/, /\.help/, /\.load/,