Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var MOVE_LEFT = new Buffer('1b5b3130303044', 'hex').toString();
var MOVE_UP = new Buffer('1b5b3141', 'hex').toString();
var CLEAR_LINE = new Buffer('1b5b304b', 'hex').toString();
var stringWidth = require('string-width');
Expand All @@ -23,9 +22,9 @@ module.exports = function(stream) {
str = '';
var nextStr = Array.prototype.join.call(arguments, ' ');

// Clear screen
// Move to beginning of line and clear, then move up for each previous line
for (var i=0; i<prevLineCount; i++) {
str += MOVE_LEFT + CLEAR_LINE + (i < prevLineCount-1 ? MOVE_UP : '');
str += '\r' + CLEAR_LINE + (i < prevLineCount-1 ? MOVE_UP : '');
}

// Actual log output
Expand All @@ -41,7 +40,7 @@ module.exports = function(stream) {
};

log.clear = function() {
stream.write('');
stream.write('\n');
};

return log;
Expand Down
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ setInterval(function() {
if (i < 30) s += '\nline 3 - ' + Math.random();
if (i < 20) s += '\nline 4 - ' + Math.random();

if (i < 10) s += '\nline 5 - Long line - ' + '*'.repeat(process.stdout.columns) + ' - ' + Math.random();

log(s);

if (i === 50) {
Expand Down