Make carriage return portable

In unix we can just use '\r';
In Windows the easiest way is to print a lot of '\b';
This commit is contained in:
Slava Kim
2014-11-11 15:19:39 -08:00
committed by Sashko Stubailo
parent c62a37c6b5
commit ccd666dc6b
3 changed files with 15 additions and 10 deletions

View File

@@ -930,12 +930,12 @@ exports.registerOrLogIn = withAccountsConnection(function (connection) {
var spinner = ['-', '\\', '|', '/'];
lastLinePrinted = "Waiting for you to register on the web... " +
spinner[animationFrame];
Console.rawError(lastLinePrinted + "\r");
Console.rawError(lastLinePrinted + Console.CARRIAGE_RETURN);
animationFrame = (animationFrame + 1) % spinner.length;
}, 200);
var stopSpinner = function () {
Console.rawError(new Array(lastLinePrinted.length + 1).join(' ') +
"\r");
Console.CARRIAGE_RETURN);
clearInterval(timer);
};

View File

@@ -69,6 +69,9 @@ var wordwrap = require('wordwrap');
var PROGRESS_DEBUG = !!process.env.METEOR_PROGRESS_DEBUG;
var FORCE_PRETTY=undefined;
var CARRIAGE_RETURN =
(process.platform === 'win32' ? new Array(249).join('\b') : '\r');
if (process.env.METEOR_PRETTY_OUTPUT) {
FORCE_PRETTY = process.env.METEOR_PRETTY_OUTPUT != '0';
}
@@ -172,7 +175,7 @@ _.extend(ProgressDisplayStatus.prototype, {
// clear some characters that we printed with a trailing `\r`.
if (self._wroteStatusMessage) {
var spaces = spacesString(TEMP_STATUS_LENGTH + 1);
self._stream.write(spaces + '\r');
self._stream.write(spaces + CARRIAGE_RETURN);
self._wroteStatusMessage = false;
}
},
@@ -203,7 +206,7 @@ _.extend(ProgressDisplayStatus.prototype, {
if (text) {
// the number of characters besides `text` here must
// be accounted for in TEMP_STATUS_LENGTH.
self._stream.write(' ( ' + text + ' ... )\r');
self._stream.write(' ( ' + text + ' ... )' + CARRIAGE_RETURN);
self._wroteStatusMessage = true;
}
}
@@ -320,7 +323,7 @@ _.extend(ProgressDisplayFull.prototype, {
depaint: function () {
var self = this;
self._stream.write(spacesString(self._printedLength) + "\r");
self._stream.write(spacesString(self._printedLength) + CARRIAGE_RETURN);
},
updateStatus: function (status) {
@@ -401,7 +404,7 @@ _.extend(ProgressDisplayFull.prototype, {
length += statusColumns;
}
line += progressGraphic + "\r";
line += progressGraphic + CARRIAGE_RETURN;
length += progressGraphic.length;
self.depaint();
@@ -1263,3 +1266,5 @@ Console.prototype.readLine = function (options) {
exports.Console = new Console;
exports.Console.CARRIAGE_RETURN = CARRIAGE_RETURN;

View File

@@ -72,7 +72,7 @@ _.extend(RunLog.prototype, {
if (self.temporaryMessageLength) {
var spaces = new Array(self.temporaryMessageLength + 1).join(' ');
process.stdout.write(spaces + '\r');
process.stdout.write(spaces + CARRIAGE_RETURN);
self.temporaryMessageLength = null;
}
},
@@ -136,7 +136,7 @@ _.extend(RunLog.prototype, {
var self = this;
self._clearSpecial();
process.stdout.write(msg + "\r");
process.stdout.write(msg + CARRIAGE_RETURN);
self.temporaryMessageLength = msg.length;
},
@@ -146,7 +146,7 @@ _.extend(RunLog.prototype, {
if (self.consecutiveRestartMessages) {
// replace old message in place. this assumes that the new restart message
// is not shorter than the old one.
process.stdout.write("\r");
process.stdout.write(CARRIAGE_RETURN);
self.messages.pop();
self.consecutiveRestartMessages ++;
} else {
@@ -173,7 +173,7 @@ _.extend(RunLog.prototype, {
if (self.consecutiveClientRestartMessages) {
// replace old message in place. this assumes that the new restart message
// is not shorter than the old one.
process.stdout.write("\r");
process.stdout.write(CARRIAGE_RETURN);
self.messages.pop();
self.consecutiveClientRestartMessages ++;
} else {