Skip to content

Commit

Permalink
Fix cursor when moved by 0
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jan 7, 2016
1 parent eaefbf1 commit 33403fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/utils/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var ansiEscapes = require('ansi-escapes');
*/

exports.left = function(rl, x) {
rl.output.write(ansiEscapes.cursorBackward(x));
if (x > 0) {
rl.output.write(ansiEscapes.cursorBackward(x));
}
};

/**
Expand All @@ -18,7 +20,9 @@ exports.left = function(rl, x) {
*/

exports.right = function(rl, x) {
rl.output.write(ansiEscapes.cursorForward(x));
if (x > 0) {
rl.output.write(ansiEscapes.cursorForward(x));
}
};

/**
Expand All @@ -28,7 +32,9 @@ exports.right = function(rl, x) {
*/

exports.up = function (rl, x) {
rl.output.write(ansiEscapes.cursorUp(x));
if (x > 0) {
rl.output.write(ansiEscapes.cursorUp(x));
}
};

/**
Expand All @@ -38,7 +44,9 @@ exports.up = function (rl, x) {
*/

exports.down = function (rl, x) {
rl.output.write(ansiEscapes.cursorDown(x));
if (x > 0) {
rl.output.write(ansiEscapes.cursorDown(x));
}
};

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/screen-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ ScreenManager.prototype.render = function (content, bottomContent) {
* Re-adjust the cursor at the correct position.
*/

// We need to consider parts of the prompt under the cursor as part of the bottom
// content in order to correctly cleanup and re-render.
var promptLineUpDiff = Math.floor(rawPromptLine.length / cliWidth()) - cursorPos.rows;
var bottomContentHeight = promptLineUpDiff + (bottomContent ? bottomContent.split('\n').length : 0);
if (bottomContentHeight > 0) {
Expand Down

2 comments on commit 33403fc

@sindresorhus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SBoudrias Sorry, this is just a stupid bug in ansi-escapes... Fixed now, so I guess you can revert most of this. sindresorhus/ansi-escapes@6c0f6a5

@SBoudrias
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

Please sign in to comment.