add a buffering write function for program.

This commit is contained in:
Christopher Jeffrey 2013-07-24 13:23:35 -05:00
parent 2f7967031e
commit 0372788f2d

View File

@ -78,6 +78,8 @@ function Program(options) {
this.setupTput(); this.setupTput();
} }
this.__flush = this._flush.bind(this);
this.listen(); this.listen();
} }
@ -1162,13 +1164,37 @@ Program.prototype._parseChar = function(text, attr) {
} }
}; };
Program.prototype.write = Program.prototype.echo_ =
Program.prototype.echo = function(text, attr) { Program.prototype.write_ = function(text, attr) {
// if (this.output === process.stdout) { if (!text) return;
// return attr
// ? Program._write.call(this.output, this.text(text, attr)) if (attr) {
// : Program._write.call(this.output, text); text = this.text(text, attr);
// } }
if (this._buf) {
this._buf += text;
return true;
}
this._buf = text;
//if (!this.__flush) {
// this.__flush = this._flush.bind(this);
//}
process.nextTick(this.__flush);
return true;
};
Program.prototype._flush = function() {
this.output.write(this._buf);
this._buf = '';
};
Program.prototype.echo =
Program.prototype.write = function(text, attr) {
return attr return attr
? this.output.write(this.text(text, attr)) ? this.output.write(this.text(text, attr))
: this.output.write(text); : this.output.write(text);
@ -1261,7 +1287,7 @@ Program.prototype.repeat = function(ch, i) {
//Program.prototype.pad = //Program.prototype.pad =
Program.prototype.nul = function() { Program.prototype.nul = function() {
//if (this.has('pad')) return this.put.pad(); //if (this.has('pad')) return this.put.pad();
return this.write('\0'); return this.write('\200');
}; };
Program.prototype.bel = Program.prototype.bel =