Skip to content

Commit

Permalink
only do console.log() mode, fix double \n bug
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 19, 2012
1 parent 8a16a96 commit 028e858
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/default_stream.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
var Stream = require('stream');

module.exports = function () {
if (typeof process !== 'undefined' && process.stdout
&& typeof process.stdout.pipe === 'function') {
return process.stdout;
}

var out = new Stream;
out.writable = true;
var buffered = '';

out.write = function (buf) {
console.log(String(buf));
var s = buffered + String(buf);
var lines = s.split('\n');
for (var i = 0; i < lines.length - 1; i++) {
console.log(lines[i]);
}
buffered = lines[i];
};

out.destroy = function () {
out.writable = false;
out.emit('close');
};

out.end = function () {
out.end = function (msg) {
if (msg !== undefined) out.write(msg);
if (buffered) console.log(buffered);
out.writable = false;
out.emit('close');
};

Expand Down

0 comments on commit 028e858

Please sign in to comment.