Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

lib/readline.js: Fix backspace for multi-line(\n) #7128

Open
wants to merge 2 commits into from

4 participants

@Benjamin-Waters

Add additional parameter to cursorTo in _refreshLine to ensure that
the cursor moves to the top left row as well as the far left column
This prevents multi-line output from repeating previous lines.

Calculate the cursor position relative to the last line by splitting
the prompt text on newline characters.

Fixes joyent/node#6415

@Benjamin-Waters Benjamin-Waters lib/readline.js: Fix backspace for multi-line(\n)
Add additional parameter to cursorTo in _refreshLine to ensure that
the cursor moves to the top left row as well as the far left column
This prevents multi-line output from repeating previous lines.

Calculate the cursor position relative to the last line by splitting
the prompt text on newline characters.

Fixes joyent/node#6415
b5cc0f2
@indutny
Owner

Could you please try running make jslint and fix all the issues in submitted changed that it'll point to? Otherwise it looks good, but would be cool to see a test before landing it.

@Benjamin-Waters

Updated as per 'make jslint'

I'll look into creating a test for it.

@trevnorris trevnorris added the readline label
@Benjamin-Waters Benjamin-Waters lib/readline.js: Fix backspace for multi-line(\n)
Add additional parameter to cursorTo in _refreshLine to ensure that
the cursor moves to the top left row as well as the far left column
This prevents multi-line output from repeating previous lines.

Calculate the cursor position relative to the last line by splitting
the prompt text on newline characters.

Fixes joyent/node#6415
eed85d7
@balupton

Any status on this? I've run into this building cli tools as well.

@indutny
Owner

Sorry for a long waiting... Could you please provide a test for it? Please let me know if you need any help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2014
  1. @Benjamin-Waters

    lib/readline.js: Fix backspace for multi-line(\n)

    Benjamin-Waters authored
    Add additional parameter to cursorTo in _refreshLine to ensure that
    the cursor moves to the top left row as well as the far left column
    This prevents multi-line output from repeating previous lines.
    
    Calculate the cursor position relative to the last line by splitting
    the prompt text on newline characters.
    
    Fixes joyent/node#6415
Commits on Feb 18, 2014
  1. @Benjamin-Waters

    lib/readline.js: Fix backspace for multi-line(\n)

    Benjamin-Waters authored
    Add additional parameter to cursorTo in _refreshLine to ensure that
    the cursor moves to the top left row as well as the far left column
    This prevents multi-line output from repeating previous lines.
    
    Calculate the cursor position relative to the last line by splitting
    the prompt text on newline characters.
    
    Fixes joyent/node#6415
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/readline.js
View
6 lib/readline.js
@@ -228,7 +228,7 @@ Interface.prototype._refreshLine = function() {
}
// Cursor to left edge.
- exports.cursorTo(this.output, 0);
+ exports.cursorTo(this.output, 0, 0);
// erase data
exports.clearScreenDown(this.output);
@@ -580,7 +580,9 @@ Interface.prototype._getDisplayPos = function(str) {
// Returns current cursor's position and line
Interface.prototype._getCursorPos = function() {
var columns = this.columns;
- var strBeforeCursor = this._prompt + this.line.substring(0, this.cursor);
+ var linesOfPrompt = this._prompt.split('\n');
+ var strBeforeCursor = linesOfPrompt[linesOfPrompt.length - 1];
+ strBeforeCursor += this.line.substring(0, this.cursor);
var dispPos = this._getDisplayPos(stripVTControlCharacters(strBeforeCursor));
var cols = dispPos.cols;
var rows = dispPos.rows;
Something went wrong with that request. Please try again.