refactor constructors.
This commit is contained in:
parent
d3c34f6f89
commit
598be3bb88
|
@ -34,10 +34,6 @@ function Program(options) {
|
|||
};
|
||||
}
|
||||
|
||||
if (options.tput !== false) {
|
||||
options.tput = true;
|
||||
}
|
||||
|
||||
this.options = options;
|
||||
this.input = options.input || process.stdin;
|
||||
this.output = options.output || process.stdout;
|
||||
|
@ -49,6 +45,7 @@ function Program(options) {
|
|||
}
|
||||
|
||||
this.zero = options.zero !== false;
|
||||
this.useBuffer = options.buffer;
|
||||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
|
@ -82,7 +79,7 @@ function Program(options) {
|
|||
Program.global = this;
|
||||
}
|
||||
|
||||
if (options.tput) {
|
||||
if (options.tput !== false) {
|
||||
this.setupTput();
|
||||
}
|
||||
|
||||
|
@ -179,6 +176,9 @@ Program.prototype.setupDump = function() {
|
|||
};
|
||||
|
||||
Program.prototype.setupTput = function() {
|
||||
if (this._tputSetup) return;
|
||||
this._tputSetup = true;
|
||||
|
||||
var self = this
|
||||
, options = this.options
|
||||
, write = this.write.bind(this);
|
||||
|
@ -1270,7 +1270,7 @@ Program.prototype.flush = function(text) {
|
|||
|
||||
Program.prototype._write = function(text) {
|
||||
if (this.ret) return text;
|
||||
if (this.options.buffer) {
|
||||
if (this.useBuffer) {
|
||||
return this._buffer(text);
|
||||
}
|
||||
return this.output.write(text);
|
||||
|
|
|
@ -266,11 +266,28 @@ function Screen(options) {
|
|||
options = { program: options };
|
||||
}
|
||||
|
||||
options.tput = true;
|
||||
options.buffer = true;
|
||||
options.program = options.program
|
||||
|| require('./program').global
|
||||
|| new (require('./program'))(options);
|
||||
var program = require('./program');
|
||||
|
||||
this.program = options.program || program.global;
|
||||
|
||||
if (!this.program) {
|
||||
this.program = program({
|
||||
input: options.input,
|
||||
output: options.output,
|
||||
log: options.log,
|
||||
debug: options.debug,
|
||||
dump: options.dump,
|
||||
tput: true,
|
||||
buffer: true,
|
||||
zero: true
|
||||
});
|
||||
} else {
|
||||
this.program.setupTput();
|
||||
this.program.useBuffer = true;
|
||||
this.program.zero = true;
|
||||
}
|
||||
|
||||
this.tput = this.program.tput;
|
||||
|
||||
if (!Screen.global) {
|
||||
Screen.global = this;
|
||||
|
@ -278,13 +295,9 @@ function Screen(options) {
|
|||
|
||||
Node.call(this, options);
|
||||
|
||||
this.program = options.program;
|
||||
this.program.zero = true;
|
||||
this.tput = this.program.tput;
|
||||
|
||||
this.autoPadding = options.autoPadding;
|
||||
|
||||
this.tabc = Array((options.tabSize || 4) + 1).join(' ');
|
||||
|
||||
this.dattr = ((0 << 18) | (0x1ff << 9)) | 0x1ff;
|
||||
|
||||
this.position = {
|
||||
|
@ -844,7 +857,9 @@ Screen.prototype.draw = function(start, end) {
|
|||
, bg
|
||||
, flags;
|
||||
|
||||
var main = '';
|
||||
var main = ''
|
||||
, pre
|
||||
, post;
|
||||
|
||||
var clr
|
||||
, neq
|
||||
|
@ -1127,8 +1142,8 @@ Screen.prototype.draw = function(start, end) {
|
|||
}
|
||||
|
||||
if (main) {
|
||||
var pre = ''
|
||||
, post = '';
|
||||
pre = '';
|
||||
post = '';
|
||||
|
||||
pre += this.tput
|
||||
? this.tput.sc()
|
||||
|
|
Loading…
Reference in New Issue