From 8517089b3e1eb7cd3cd1a77666c1de756fd752a3 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 20 Mar 2012 15:04:18 -0700 Subject: [PATCH] Revert "readline: add multiline support" This reverts commit 443071db5749603f816199b9ec8bc512fb441d98. Patch was overly compilicated and made some incorrect assumptions about the position of the cursor being at the bottom of the screen. @rlidwka and I are working on getting a proper implementation written. --- lib/readline.js | 86 +++++-------------------------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index 6c867c4496..f0504c8db5 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -95,18 +95,13 @@ function Interface(input, output, completer) { this.history = []; this.historyIndex = -1; - // a number of lines used by current command - this.usedLines = 1; - var winSize = output.getWindowSize(); exports.columns = winSize[0]; - exports.rows = winSize[1]; if (process.listeners('SIGWINCH').length === 0) { process.on('SIGWINCH', function() { var winSize = output.getWindowSize(); exports.columns = winSize[0]; - exports.rows = winSize[1]; }); } } @@ -118,10 +113,6 @@ Interface.prototype.__defineGetter__('columns', function() { return exports.columns; }); -Interface.prototype.__defineGetter__('rows', function() { - return exports.rows; -}); - Interface.prototype.setPrompt = function(prompt, length) { this._prompt = prompt; if (length) { @@ -187,53 +178,19 @@ Interface.prototype._addHistory = function() { }; -Interface.prototype._recalcUsedLines = function() { - var line = this._prompt + this.line; - var newcount = Math.ceil(line.length / this.columns); - if (newcount > this.usedLines) this.usedLines = newcount; -}; - - Interface.prototype._refreshLine = function() { - var columns = this.columns; - if (!columns) columns = Infinity; - - // See if a number of used lines has changed - var oldLines = this.usedLines; - this._recalcUsedLines(); - if (oldLines != this.usedLines) { - this.output.cursorTo(0, this.rows - 1); - for (var i = oldLines; i < this.usedLines; i++) { - this.output.write('\r\n'); - } - } - // Cursor to left edge. - if (this.usedLines === 1) { - this.output.cursorTo(0); - } else { - this.output.cursorTo(0, this.rows - this.usedLines); - } + this.output.cursorTo(0); // Write the prompt and the current buffer content. - var buffer = this._prompt + this.line; - this.output.write(buffer); + this.output.write(this._prompt); + this.output.write(this.line); // Erase to right. this.output.clearLine(1); - var clearLinesCnt = this.usedLines - Math.floor(buffer.length / columns) - 1; - for (var i = this.rows - clearLinesCnt; i < this.rows; i++) { - this.output.cursorTo(0, i); - this.output.clearLine(0); - } // Move cursor to original position. - var curPos = this._getCursorPos(); - if (this.usedLines === 1) { - this.output.cursorTo(curPos[0]); - } else { - this.output.cursorTo(curPos[0], this.rows - this.usedLines + curPos[1]); - } + this.output.cursorTo(this._promptLength + this.cursor); }; @@ -285,7 +242,6 @@ Interface.prototype._insertString = function(c) { this.line += c; this.cursor += c.length; this.output.write(c); - this._recalcUsedLines(); } }; @@ -459,7 +415,6 @@ Interface.prototype._deleteLineRight = function() { Interface.prototype._line = function() { var line = this._addHistory(); this.output.write('\r\n'); - this.usedLines = 1; this._onLine(line); }; @@ -491,33 +446,6 @@ Interface.prototype._historyPrev = function() { }; -// Returns current cursor's position and line -Interface.prototype._getCursorPos = function() { - var columns = this.columns; - var pos = this.cursor + this._promptLength; - if (!columns) return [pos, 0]; - - var lineNum = Math.floor(pos / columns); - var colNum = pos - lineNum * columns; - return [colNum, lineNum]; -}; - - -Interface.prototype._moveCursor = function(dx) { - var oldcursor = this.cursor; - var oldLine = this._getCursorPos()[1]; - this.cursor += dx; - var newLine = this._getCursorPos()[1]; - - // check if cursors are in the same line - if (oldLine == newLine) { - this.output.moveCursor(dx, 0); - } else { - this._refreshLine(); - } -}; - - // handle a write from the tty Interface.prototype._ttyWrite = function(s, key) { var next_word, next_non_word, previous_word, previous_non_word; @@ -691,13 +619,15 @@ Interface.prototype._ttyWrite = function(s, key) { case 'left': if (this.cursor > 0) { - this._moveCursor(-1); + this.cursor--; + this.output.moveCursor(-1, 0); } break; case 'right': if (this.cursor != this.line.length) { - this._moveCursor(1); + this.cursor++; + this.output.moveCursor(1, 0); } break;