emit more events. use tput.

This commit is contained in:
Christopher Jeffrey 2013-06-11 13:13:49 -05:00
parent 495060e074
commit 02c57a34ce
4 changed files with 35 additions and 25 deletions

View File

@ -161,6 +161,7 @@ The base node which everything inherits from.
##### Events:
- inherits all from EventEmitter.
- **adopt** - received when node is added to a parent.
- **remove** - received when node is removed from it's current parent.
- **reparent** - received when node gains a new parent.

View File

@ -41,7 +41,7 @@ function Program(options) {
this.cols = this.output.columns || 1;
this.rows = this.output.rows || 1;
this.terminal = process.env.TERM || 'xterm';
this.terminal = options.terminal || process.env.TERM || 'xterm';
if (options.tput) {
this.setupTput();
@ -1445,7 +1445,7 @@ Program.prototype._attr = function(param, val) {
return this._attr('default ' + m[2]);
}
if (color < 16 || this.tput.colors <= 16) {
if (color < 16 || (this.tput && this.tput.colors <= 16)) {
if (m[2] === 'fg') {
if (color < 8) {
color += 30;

View File

@ -44,8 +44,8 @@ Node.prototype.prepend = function(element) {
this.children.unshift(element);
}
// element.emit('reparent', this);
// this.emit('append', element);
element.emit('reparent', this);
this.emit('adopt', element);
};
Node.prototype.append = function(element) {
@ -59,8 +59,8 @@ Node.prototype.append = function(element) {
this.children.push(element);
}
// element.emit('reparent', this);
// this.emit('append', element);
element.emit('reparent', this);
this.emit('adopt', element);
};
Node.prototype.remove = function(element) {
@ -75,8 +75,8 @@ Node.prototype.remove = function(element) {
this.focused = this.children[0];
}
// element.emit('reparent', null);
// this.emit('remove', element);
element.emit('reparent', null);
this.emit('remove', element);
};
Node.prototype.detach = function(element) {
@ -261,7 +261,7 @@ Screen.prototype.render = function() {
el.render();
});
this.draw(0, this.rows - 1);
// this.emit('draw');
this.emit('draw');
};
Screen.prototype.draw = function(start, end) {
@ -304,12 +304,15 @@ Screen.prototype.draw = function(start, end) {
}
continue;
} else if (lx !== -1) {
//out += y === ly
// ? this.program.cuf(x - lx)
// : this.program.cup(y, x);
out += y === ly
? '\x1b[' + (x - lx) + 'C'
: '\x1b[' + (y + 1) + ';' + (x + 1) + 'H';
if (this.tput) {
out += y === ly
? this.tput.cuf(x - lx)
: this.tput.cup(y, x);
} else {
out += y === ly
? '\x1b[' + (x - lx) + 'C'
: '\x1b[' + (y + 1) + ';' + (x + 1) + 'H';
}
lx = -1, ly = -1;
}
o[x][0] = data;
@ -352,7 +355,7 @@ Screen.prototype.draw = function(start, end) {
}
if (bgColor !== 0x1ff) {
if (bgColor < 16 || this.tput.colors <= 16) {
if (bgColor < 16 || (this.tput && this.tput.colors <= 16)) {
if (bgColor < 8) {
bgColor += 40;
} else if (bgColor < 16) {
@ -366,7 +369,7 @@ Screen.prototype.draw = function(start, end) {
}
if (fgColor !== 0x1ff) {
if (fgColor < 16 || this.tput.colors <= 16) {
if (fgColor < 16 || (this.tput && this.tput.colors <= 16)) {
if (fgColor < 8) {
fgColor += 30;
} else if (fgColor < 16) {
@ -393,8 +396,11 @@ Screen.prototype.draw = function(start, end) {
out += '\x1b[m';
}
//if (out) this.program.write(this.tput.cup(y, 1) + out);
if (out) this.program.write('\x1b[' + (y + 1) + ';1H' + out);
if (this.tput) {
if (out) this.program.write(this.tput.cup(y, 0) + out);
} else {
if (out) this.program.write('\x1b[' + (y + 1) + ';1H' + out);
}
}
this.program.restoreCursor();
@ -571,13 +577,13 @@ Element.prototype.hide = function() {
var ret = this.render(true);
this.hidden = true;
this.screen.clearRegion(ret.xi, ret.xl, ret.yi, ret.yl);
// this.emit('hide');
this.emit('hide');
};
Element.prototype.show = function() {
this.hidden = false;
//this.render();
// this.emit('show');
this.emit('show');
};
Element.prototype.toggle = function() {
@ -768,7 +774,9 @@ Element.prototype.__defineSetter__('left', function(val) {
//val = val - this.parent.left;
}
this.emit('move');
this.screen.clearRegion(this.left, this.left + this.width, this.top, this.top + this.height);
this.screen.clearRegion(
this.left, this.left + this.width,
this.top, this.top + this.height);
//var left = this.left;
//return this.options.left = this.position.left = left + (val - left);
return this.options.left = this.position.left = val - this.parent.left;
@ -1283,7 +1291,9 @@ function List(options) {
}
// self.on('keypress', function(ch, key) {
// if (key.name === 'enter') self.emit('select');
// if (key.name === 'enter') {
// self.emit('select', self.items[self.selected], self.selected);
// }
// });
}
@ -1444,7 +1454,6 @@ ScrollableText.prototype.scroll = function(offset) {
max = this._content.length - 1 - (this.height - (this.border ? 2 : 0));
if (cb > max) this.childBase = cb = max;
// Faster:
if (diff > 0) {
for (i = base; i < cb; i++) this.contentIndex += this._content[i].length + 1;
} else {

View File

@ -1,5 +1,5 @@
var blessed = require('blessed')
, program = blessed();
, program = blessed({ tput: true });
var screen = new blessed.Screen({
program: program