Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repl: make turnO[n|ff]EditorMode private functions
This deprecates the current REPLServer.prototype.turnOffEditorMode
  • Loading branch information
lance committed Sep 27, 2017
commit fd4ffb80cc3a38f3cbbd677cbbf485ed3a397fcb
34 changes: 19 additions & 15 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function REPLServer(prompt,
self.on('SIGINT', function onSigInt() {
var empty = self.line.length === 0;
self.clearLine();
self.turnOffEditorMode();
_turnOffEditorMode.call(self);

const cmd = self[kBufferedCommandSymbol];
if (!(cmd && cmd.length > 0) && empty) {
Expand Down Expand Up @@ -539,7 +539,7 @@ function REPLServer(prompt,
if (key.ctrl && !key.shift) {
switch (key.name) {
case 'd': // End editor mode
self.turnOffEditorMode();
_turnOffEditorMode.call(self);
sawCtrlD = true;
ttyWrite(d, { name: 'return' });
break;
Expand Down Expand Up @@ -691,16 +691,10 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) {
REPLServer.super_.prototype.setPrompt.call(this, prompt);
};

REPLServer.prototype.turnOffEditorMode = function() {
this.editorMode = false;
this.setPrompt(this._initialPrompt);
};

REPLServer.prototype.turnOnEditorMode = function() {
this.editorMode = true;
REPLServer.super_.prototype.setPrompt.call(this, '');
};

REPLServer.prototype.turnOffEditorMode = util.deprecate(
_turnOffEditorMode,
'REPLServer.turnOffEditorMode() is deprecated',
'DEP00XX');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation must be documented as well in the deprecations.md.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and deprecations are semver-major.


// A stream to push an array into a REPL
// used in REPLServer.complete
Expand Down Expand Up @@ -1187,6 +1181,16 @@ function addStandardGlobals(completionGroups, filter) {
}
}

function _turnOnEditorMode(repl) {
repl.editorMode = true;
REPLServer.super_.prototype.setPrompt.call(repl, '');
}

function _turnOffEditorMode() {
this.editorMode = false;
this.setPrompt(this._initialPrompt);
}

function defineDefaultCommands(repl) {
repl.defineCommand('break', {
help: 'Sometimes you get stuck, this gets you out',
Expand Down Expand Up @@ -1259,14 +1263,14 @@ function defineDefaultCommands(repl) {
try {
var stats = fs.statSync(file);
if (stats && stats.isFile()) {
this.turnOnEditorMode();
_turnOnEditorMode(this);
var data = fs.readFileSync(file, 'utf8');
var lines = data.split('\n');
for (var n = 0; n < lines.length; n++) {
if (lines[n])
this.write(`${lines[n]}\n`);
}
this.turnOffEditorMode();
_turnOffEditorMode.call(this);
this.write('\n');
} else {
this.outputStream.write('Failed to load:' + file +
Expand All @@ -1283,7 +1287,7 @@ function defineDefaultCommands(repl) {
help: 'Enter editor mode',
action() {
if (!this.terminal) return;
this.turnOnEditorMode();
_turnOnEditorMode(this);
this.outputStream.write(
'// Entering editor mode (^D to finish, ^C to cancel)\n');
}
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-repl-turn-off-editor-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
const assert = require('assert');
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();
}