Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "readline: add multiline support"
This reverts commit 443071d.

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.
  • Loading branch information
TooTallNate committed Mar 20, 2012
1 parent 253ec6a commit 8517089
Showing 1 changed file with 8 additions and 78 deletions.
86 changes: 8 additions & 78 deletions lib/readline.js
Expand Up @@ -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];
});
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
};


Expand Down Expand Up @@ -285,7 +242,6 @@ Interface.prototype._insertString = function(c) {
this.line += c;
this.cursor += c.length;
this.output.write(c);
this._recalcUsedLines();
}
};

Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 8517089

Please sign in to comment.