Skip to content

Commit

Permalink
Make line 1 char shorter to prevent windows from auto line returning
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jan 11, 2016
1 parent 75995f5 commit 8667f7a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/utils/screen-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ function lastLine(content) {
return _.last(content.split('\n'));
}

function normalizedCliWidth() {
if (process.platform === 'win32') {
return cliWidth() - 1;
}
return cliWidth();
}

var ScreenManager = module.exports = function (rl) {
// These variables are keeping information to allow correct prompt re-rendering
this.height = 0;
Expand Down Expand Up @@ -56,7 +63,7 @@ ScreenManager.prototype.render = function (content, bottomContent) {
// Manually insert an extra line if we're at the end of the line.
// This prevent the cursor from appearing at the beginning of the
// current line.
if (rawPromptLine.length % cliWidth() === 0) {
if (rawPromptLine.length % normalizedCliWidth() === 0) {
content = content + '\n';
}
var fullContent = content + (bottomContent ? '\n' + bottomContent : '');
Expand All @@ -68,7 +75,7 @@ ScreenManager.prototype.render = function (content, bottomContent) {

// 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 promptLineUpDiff = Math.floor(rawPromptLine.length / normalizedCliWidth()) - cursorPos.rows;
var bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
if (bottomContentHeight > 0) {
util.up(this.rl, bottomContentHeight);
Expand Down Expand Up @@ -109,7 +116,7 @@ ScreenManager.prototype.done = function () {
function breakLines(lines) {
// Break lines who're longuer than the cli width so we can normalize the natural line
// returns behavior accross terminals.
var width = cliWidth();
var width = normalizedCliWidth();
var regex = new RegExp(
'(?:(?:\\033\[[0-9;]*m)*.?){1,' + width + '}',
'g'
Expand Down

0 comments on commit 8667f7a

Please sign in to comment.