Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readline: named anonymous functions in readline.js #21759

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
60 changes: 30 additions & 30 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ Object.defineProperty(Interface.prototype, 'columns', {
}
});

Interface.prototype.setPrompt = function(prompt) {
Interface.prototype.setPrompt = function setPrompt(prompt) {
this._prompt = prompt;
};


Interface.prototype._setRawMode = function(mode) {
Interface.prototype._setRawMode = function _setRawMode(mode) {
const wasInRawMode = this.input.isRaw;

if (typeof this.input.setRawMode === 'function') {
Expand All @@ -255,7 +255,7 @@ Interface.prototype._setRawMode = function(mode) {
};


Interface.prototype.prompt = function(preserveCursor) {
Interface.prototype.prompt = function prompt(preserveCursor) {
if (this.paused) this.resume();
if (this.terminal) {
if (!preserveCursor) this.cursor = 0;
Expand All @@ -266,7 +266,7 @@ Interface.prototype.prompt = function(preserveCursor) {
};


Interface.prototype.question = function(query, cb) {
Interface.prototype.question = function question(query, cb) {
if (typeof cb === 'function') {
if (this._questionCallback) {
this.prompt();
Expand All @@ -280,7 +280,7 @@ Interface.prototype.question = function(query, cb) {
};


Interface.prototype._onLine = function(line) {
Interface.prototype._onLine = function _onLine(line) {
if (this._questionCallback) {
var cb = this._questionCallback;
this._questionCallback = null;
Expand All @@ -301,7 +301,7 @@ Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
}
};

Interface.prototype._addHistory = function() {
Interface.prototype._addHistory = function _addHistory() {
if (this.line.length === 0) return '';

// if the history is disabled then return the line
Expand All @@ -328,7 +328,7 @@ Interface.prototype._addHistory = function() {
};


Interface.prototype._refreshLine = function() {
Interface.prototype._refreshLine = function _refreshLine() {
// line length
var line = this._prompt + this.line;
var dispPos = this._getDisplayPos(line);
Expand Down Expand Up @@ -369,7 +369,7 @@ Interface.prototype._refreshLine = function() {
};


Interface.prototype.close = function() {
Interface.prototype.close = function close() {
if (this.closed) return;
this.pause();
if (this.terminal) {
Expand All @@ -380,7 +380,7 @@ Interface.prototype.close = function() {
};


Interface.prototype.pause = function() {
Interface.prototype.pause = function pause() {
if (this.paused) return;
this.input.pause();
this.paused = true;
Expand All @@ -389,7 +389,7 @@ Interface.prototype.pause = function() {
};


Interface.prototype.resume = function() {
Interface.prototype.resume = function resume() {
if (!this.paused) return;
this.input.resume();
this.paused = false;
Expand All @@ -398,12 +398,12 @@ Interface.prototype.resume = function() {
};


Interface.prototype.write = function(d, key) {
Interface.prototype.write = function write(d, key) {
if (this.paused) this.resume();
this.terminal ? this._ttyWrite(d, key) : this._normalWrite(d);
};

Interface.prototype._normalWrite = function(b) {
Interface.prototype._normalWrite = function _normalWrite(b) {
if (b === undefined) {
return;
}
Expand Down Expand Up @@ -437,7 +437,7 @@ Interface.prototype._normalWrite = function(b) {
}
};

Interface.prototype._insertString = function(c) {
Interface.prototype._insertString = function _insertString(c) {
if (this.cursor < this.line.length) {
var beg = this.line.slice(0, this.cursor);
var end = this.line.slice(this.cursor, this.line.length);
Expand All @@ -459,7 +459,7 @@ Interface.prototype._insertString = function(c) {
}
};

Interface.prototype._tabComplete = function(lastKeypressWasTab) {
Interface.prototype._tabComplete = function _tabComplete(lastKeypressWasTab) {
var self = this;

self.pause();
Expand Down Expand Up @@ -551,7 +551,7 @@ function commonPrefix(strings) {
}


Interface.prototype._wordLeft = function() {
Interface.prototype._wordLeft = function _wordLeft() {
if (this.cursor > 0) {
var leading = this.line.slice(0, this.cursor);
var match = leading.match(/(?:[^\w\s]+|\w+|)\s*$/);
Expand All @@ -560,7 +560,7 @@ Interface.prototype._wordLeft = function() {
};


Interface.prototype._wordRight = function() {
Interface.prototype._wordRight = function _wordRight() {
if (this.cursor < this.line.length) {
var trailing = this.line.slice(this.cursor);
var match = trailing.match(/^(?:\s+|\W+|\w+)\s*/);
Expand All @@ -569,7 +569,7 @@ Interface.prototype._wordRight = function() {
};


Interface.prototype._deleteLeft = function() {
Interface.prototype._deleteLeft = function _deleteLeft() {
if (this.cursor > 0 && this.line.length > 0) {
this.line = this.line.slice(0, this.cursor - 1) +
this.line.slice(this.cursor, this.line.length);
Expand All @@ -580,14 +580,14 @@ Interface.prototype._deleteLeft = function() {
};


Interface.prototype._deleteRight = function() {
Interface.prototype._deleteRight = function _deleteRight() {
this.line = this.line.slice(0, this.cursor) +
this.line.slice(this.cursor + 1, this.line.length);
this._refreshLine();
};


Interface.prototype._deleteWordLeft = function() {
Interface.prototype._deleteWordLeft = function _deleteWordLeft() {
if (this.cursor > 0) {
var leading = this.line.slice(0, this.cursor);
var match = leading.match(/(?:[^\w\s]+|\w+|)\s*$/);
Expand All @@ -599,7 +599,7 @@ Interface.prototype._deleteWordLeft = function() {
};


Interface.prototype._deleteWordRight = function() {
Interface.prototype._deleteWordRight = function _deleteWordRight() {
if (this.cursor < this.line.length) {
var trailing = this.line.slice(this.cursor);
var match = trailing.match(/^(?:\s+|\W+|\w+)\s*/);
Expand All @@ -610,20 +610,20 @@ Interface.prototype._deleteWordRight = function() {
};


Interface.prototype._deleteLineLeft = function() {
Interface.prototype._deleteLineLeft = function _deleteLineLeft() {
this.line = this.line.slice(this.cursor);
this.cursor = 0;
this._refreshLine();
};


Interface.prototype._deleteLineRight = function() {
Interface.prototype._deleteLineRight = function _deleteLineRight() {
this.line = this.line.slice(0, this.cursor);
this._refreshLine();
};


Interface.prototype.clearLine = function() {
Interface.prototype.clearLine = function clearLine() {
this._moveCursor(+Infinity);
this._writeToOutput('\r\n');
this.line = '';
Expand All @@ -632,14 +632,14 @@ Interface.prototype.clearLine = function() {
};


Interface.prototype._line = function() {
Interface.prototype._line = function _line() {
var line = this._addHistory();
this.clearLine();
this._onLine(line);
};


Interface.prototype._historyNext = function() {
Interface.prototype._historyNext = function _historyNext() {
if (this.historyIndex > 0) {
this.historyIndex--;
this.line = this.history[this.historyIndex];
Expand All @@ -655,7 +655,7 @@ Interface.prototype._historyNext = function() {
};


Interface.prototype._historyPrev = function() {
Interface.prototype._historyPrev = function _historyPrev() {
if (this.historyIndex + 1 < this.history.length) {
this.historyIndex++;
this.line = this.history[this.historyIndex];
Expand All @@ -667,7 +667,7 @@ Interface.prototype._historyPrev = function() {


// Returns the last character's display position of the given string
Interface.prototype._getDisplayPos = function(str) {
Interface.prototype._getDisplayPos = function _getDisplayPos(str) {
var offset = 0;
var col = this.columns;
var row = 0;
Expand Down Expand Up @@ -700,7 +700,7 @@ Interface.prototype._getDisplayPos = function(str) {


// Returns current cursor's position and line
Interface.prototype._getCursorPos = function() {
Interface.prototype._getCursorPos = function _getCursorPos() {
var columns = this.columns;
var strBeforeCursor = this._prompt + this.line.substring(0, this.cursor);
var dispPos = this._getDisplayPos(stripVTControlCharacters(strBeforeCursor));
Expand All @@ -720,7 +720,7 @@ Interface.prototype._getCursorPos = function() {

// This function moves cursor dx places to the right
// (-dx for left) and refreshes the line if it is needed
Interface.prototype._moveCursor = function(dx) {
Interface.prototype._moveCursor = function _moveCursor(dx) {
var oldcursor = this.cursor;
var oldPos = this._getCursorPos();
this.cursor += dx;
Expand Down Expand Up @@ -753,7 +753,7 @@ Interface.prototype._moveCursor = function(dx) {


// handle a write from the tty
Interface.prototype._ttyWrite = function(s, key) {
Interface.prototype._ttyWrite = function _ttyWrite(s, key) {
const previousKey = this._previousKey;
key = key || {};
this._previousKey = key;
Expand Down