Skip to content

Commit e416b3e

Browse files
lanceBridgeAR
authored andcommitted
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: #15136 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Prince John Wesley <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a1b6cfd commit e416b3e

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

doc/api/deprecations.md

+7
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,13 @@ Type: Runtime
693693
694694
*Note*: `Module._debug()` was never documented as an officially supported API.
695695
696+
<a id="DEP0078"></a>
697+
### DEP0078: REPLServer.turnOffEditorMode()
698+
699+
Type: Runtime
700+
701+
`REPLServer.turnOffEditorMode()` was removed from userland visibility.
702+
696703
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
697704
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
698705
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer

lib/repl.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ function REPLServer(prompt,
397397
self.on('SIGINT', function onSigInt() {
398398
var empty = self.line.length === 0;
399399
self.clearLine();
400-
self.turnOffEditorMode();
400+
_turnOffEditorMode(self);
401401

402402
const cmd = self[kBufferedCommandSymbol];
403403
if (!(cmd && cmd.length > 0) && empty) {
@@ -539,7 +539,7 @@ function REPLServer(prompt,
539539
if (key.ctrl && !key.shift) {
540540
switch (key.name) {
541541
case 'd': // End editor mode
542-
self.turnOffEditorMode();
542+
_turnOffEditorMode(self);
543543
sawCtrlD = true;
544544
ttyWrite(d, { name: 'return' });
545545
break;
@@ -691,11 +691,10 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) {
691691
REPLServer.super_.prototype.setPrompt.call(this, prompt);
692692
};
693693

694-
REPLServer.prototype.turnOffEditorMode = function() {
695-
this.editorMode = false;
696-
this.setPrompt(this._initialPrompt);
697-
};
698-
694+
REPLServer.prototype.turnOffEditorMode = util.deprecate(
695+
function() { _turnOffEditorMode(this); },
696+
'REPLServer.turnOffEditorMode() is deprecated',
697+
'DEP00XX');
699698

700699
// A stream to push an array into a REPL
701700
// used in REPLServer.complete
@@ -1182,6 +1181,16 @@ function addStandardGlobals(completionGroups, filter) {
11821181
}
11831182
}
11841183

1184+
function _turnOnEditorMode(repl) {
1185+
repl.editorMode = true;
1186+
REPLServer.super_.prototype.setPrompt.call(repl, '');
1187+
}
1188+
1189+
function _turnOffEditorMode(repl) {
1190+
repl.editorMode = false;
1191+
repl.setPrompt(repl._initialPrompt);
1192+
}
1193+
11851194
function defineDefaultCommands(repl) {
11861195
repl.defineCommand('break', {
11871196
help: 'Sometimes you get stuck, this gets you out',
@@ -1254,15 +1263,14 @@ function defineDefaultCommands(repl) {
12541263
try {
12551264
var stats = fs.statSync(file);
12561265
if (stats && stats.isFile()) {
1257-
this.editorMode = true;
1258-
REPLServer.super_.prototype.setPrompt.call(this, '');
1266+
_turnOnEditorMode(this);
12591267
var data = fs.readFileSync(file, 'utf8');
12601268
var lines = data.split('\n');
12611269
for (var n = 0; n < lines.length; n++) {
12621270
if (lines[n])
12631271
this.write(`${lines[n]}\n`);
12641272
}
1265-
this.turnOffEditorMode();
1273+
_turnOffEditorMode(this);
12661274
this.write('\n');
12671275
} else {
12681276
this.outputStream.write('Failed to load:' + file +
@@ -1279,8 +1287,7 @@ function defineDefaultCommands(repl) {
12791287
help: 'Enter editor mode',
12801288
action() {
12811289
if (!this.terminal) return;
1282-
this.editorMode = true;
1283-
REPLServer.super_.prototype.setPrompt.call(this, '');
1290+
_turnOnEditorMode(this);
12841291
this.outputStream.write(
12851292
'// Entering editor mode (^D to finish, ^C to cancel)\n');
12861293
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const common = require('../common');
3+
const repl = require('repl');
4+
5+
testTurnOffEditorMode();
6+
7+
function testTurnOffEditorMode() {
8+
const server = repl.start({ prompt: '> ' });
9+
const warn = 'REPLServer.turnOffEditorMode() is deprecated';
10+
11+
common.expectWarning('DeprecationWarning', warn);
12+
server.turnOffEditorMode();
13+
server.close();
14+
}

0 commit comments

Comments
 (0)