repl: deprecate turnOffEditorMode
This deprecates the current REPLServer.prototype.turnOffEditorMode and adds a private function for turnOffEditorMode which handles the necessary internal changes required instead of having them scattered about. PR-URL: https://github.com/nodejs/node/pull/15136 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
a1b6cfd362
commit
e416b3ee36
@ -693,6 +693,13 @@ Type: Runtime
|
|||||||
|
|
||||||
*Note*: `Module._debug()` was never documented as an officially supported API.
|
*Note*: `Module._debug()` was never documented as an officially supported API.
|
||||||
|
|
||||||
|
<a id="DEP0078"></a>
|
||||||
|
### DEP0078: REPLServer.turnOffEditorMode()
|
||||||
|
|
||||||
|
Type: Runtime
|
||||||
|
|
||||||
|
`REPLServer.turnOffEditorMode()` was removed from userland visibility.
|
||||||
|
|
||||||
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
|
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
|
||||||
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
|
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
|
||||||
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
|
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
|
||||||
|
31
lib/repl.js
31
lib/repl.js
@ -397,7 +397,7 @@ function REPLServer(prompt,
|
|||||||
self.on('SIGINT', function onSigInt() {
|
self.on('SIGINT', function onSigInt() {
|
||||||
var empty = self.line.length === 0;
|
var empty = self.line.length === 0;
|
||||||
self.clearLine();
|
self.clearLine();
|
||||||
self.turnOffEditorMode();
|
_turnOffEditorMode(self);
|
||||||
|
|
||||||
const cmd = self[kBufferedCommandSymbol];
|
const cmd = self[kBufferedCommandSymbol];
|
||||||
if (!(cmd && cmd.length > 0) && empty) {
|
if (!(cmd && cmd.length > 0) && empty) {
|
||||||
@ -539,7 +539,7 @@ function REPLServer(prompt,
|
|||||||
if (key.ctrl && !key.shift) {
|
if (key.ctrl && !key.shift) {
|
||||||
switch (key.name) {
|
switch (key.name) {
|
||||||
case 'd': // End editor mode
|
case 'd': // End editor mode
|
||||||
self.turnOffEditorMode();
|
_turnOffEditorMode(self);
|
||||||
sawCtrlD = true;
|
sawCtrlD = true;
|
||||||
ttyWrite(d, { name: 'return' });
|
ttyWrite(d, { name: 'return' });
|
||||||
break;
|
break;
|
||||||
@ -691,11 +691,10 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) {
|
|||||||
REPLServer.super_.prototype.setPrompt.call(this, prompt);
|
REPLServer.super_.prototype.setPrompt.call(this, prompt);
|
||||||
};
|
};
|
||||||
|
|
||||||
REPLServer.prototype.turnOffEditorMode = function() {
|
REPLServer.prototype.turnOffEditorMode = util.deprecate(
|
||||||
this.editorMode = false;
|
function() { _turnOffEditorMode(this); },
|
||||||
this.setPrompt(this._initialPrompt);
|
'REPLServer.turnOffEditorMode() is deprecated',
|
||||||
};
|
'DEP00XX');
|
||||||
|
|
||||||
|
|
||||||
// A stream to push an array into a REPL
|
// A stream to push an array into a REPL
|
||||||
// used in REPLServer.complete
|
// used in REPLServer.complete
|
||||||
@ -1182,6 +1181,16 @@ function addStandardGlobals(completionGroups, filter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _turnOnEditorMode(repl) {
|
||||||
|
repl.editorMode = true;
|
||||||
|
REPLServer.super_.prototype.setPrompt.call(repl, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function _turnOffEditorMode(repl) {
|
||||||
|
repl.editorMode = false;
|
||||||
|
repl.setPrompt(repl._initialPrompt);
|
||||||
|
}
|
||||||
|
|
||||||
function defineDefaultCommands(repl) {
|
function defineDefaultCommands(repl) {
|
||||||
repl.defineCommand('break', {
|
repl.defineCommand('break', {
|
||||||
help: 'Sometimes you get stuck, this gets you out',
|
help: 'Sometimes you get stuck, this gets you out',
|
||||||
@ -1254,15 +1263,14 @@ function defineDefaultCommands(repl) {
|
|||||||
try {
|
try {
|
||||||
var stats = fs.statSync(file);
|
var stats = fs.statSync(file);
|
||||||
if (stats && stats.isFile()) {
|
if (stats && stats.isFile()) {
|
||||||
this.editorMode = true;
|
_turnOnEditorMode(this);
|
||||||
REPLServer.super_.prototype.setPrompt.call(this, '');
|
|
||||||
var data = fs.readFileSync(file, 'utf8');
|
var data = fs.readFileSync(file, 'utf8');
|
||||||
var lines = data.split('\n');
|
var lines = data.split('\n');
|
||||||
for (var n = 0; n < lines.length; n++) {
|
for (var n = 0; n < lines.length; n++) {
|
||||||
if (lines[n])
|
if (lines[n])
|
||||||
this.write(`${lines[n]}\n`);
|
this.write(`${lines[n]}\n`);
|
||||||
}
|
}
|
||||||
this.turnOffEditorMode();
|
_turnOffEditorMode(this);
|
||||||
this.write('\n');
|
this.write('\n');
|
||||||
} else {
|
} else {
|
||||||
this.outputStream.write('Failed to load:' + file +
|
this.outputStream.write('Failed to load:' + file +
|
||||||
@ -1279,8 +1287,7 @@ function defineDefaultCommands(repl) {
|
|||||||
help: 'Enter editor mode',
|
help: 'Enter editor mode',
|
||||||
action() {
|
action() {
|
||||||
if (!this.terminal) return;
|
if (!this.terminal) return;
|
||||||
this.editorMode = true;
|
_turnOnEditorMode(this);
|
||||||
REPLServer.super_.prototype.setPrompt.call(this, '');
|
|
||||||
this.outputStream.write(
|
this.outputStream.write(
|
||||||
'// Entering editor mode (^D to finish, ^C to cancel)\n');
|
'// Entering editor mode (^D to finish, ^C to cancel)\n');
|
||||||
}
|
}
|
||||||
|
14
test/parallel/test-repl-turn-off-editor-mode.js
Normal file
14
test/parallel/test-repl-turn-off-editor-mode.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
const repl = require('repl');
|
||||||
|
|
||||||
|
testTurnOffEditorMode();
|
||||||
|
|
||||||
|
function testTurnOffEditorMode() {
|
||||||
|
const server = repl.start({ prompt: '> ' });
|
||||||
|
const warn = 'REPLServer.turnOffEditorMode() is deprecated';
|
||||||
|
|
||||||
|
common.expectWarning('DeprecationWarning', warn);
|
||||||
|
server.turnOffEditorMode();
|
||||||
|
server.close();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user