From 960a748d703e06b78f5918c752c5c3a37e647507 Mon Sep 17 00:00:00 2001 From: justdanz Date: Wed, 11 Jul 2018 06:38:39 -0400 Subject: [PATCH] readline: named anonymous functions in readline.js Refs: https://github.com/nodejs/node/issues/8913 --- lib/readline.js | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index 835741a41a6c54..e53ccf1f1f2346 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -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') { @@ -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; @@ -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(); @@ -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; @@ -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 @@ -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); @@ -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) { @@ -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; @@ -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; @@ -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; } @@ -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); @@ -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(); @@ -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*$/); @@ -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*/); @@ -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); @@ -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*$/); @@ -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*/); @@ -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 = ''; @@ -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]; @@ -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]; @@ -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; @@ -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)); @@ -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; @@ -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;