numerous improvements.

This commit is contained in:
Christopher Jeffrey 2013-06-18 05:08:31 -05:00
parent f59f7dc0e0
commit 3d52833fa3
2 changed files with 47 additions and 16 deletions

View File

@ -27,6 +27,7 @@ function Node(options) {
|| (function(){throw new Error('No active screen.')})();
this.parent = options.parent || null; // this.screen;
this.children = [];
this.$ = this._ = this.data = {};
(options.children || []).forEach(this.append.bind(this));
@ -194,7 +195,7 @@ Screen.prototype._listenMouse = function(el) {
for (; i < self.clickable.length; i++) {
el = self.clickable[i];
if (el.hidden) continue;
if (!el.visible) continue;
// Get the true coordinates.
//ret = el.render(true);
@ -550,18 +551,23 @@ Screen.prototype._reduceColor = function(col) {
};
Screen.prototype.focus = function(offset) {
if (!this.input.length || !offset) return;
var shown = this.input.filter(function(el) {
return el.visible;
});
if (!shown || !offset) return;
var i = this.input.indexOf(this.focused);
if (!~i) return;
if (!this.input[i + offset]) {
if (offset > 0) {
while (offset--) if (++i > this.input.length - 1) i = 0;
} else {
offset = -offset;
while (offset--) if (--i < 0) i = this.input.length - 1;
while (offset--) {
if (++i > this.input.length - 1) i = 0;
if (!this.input[i].visible) offset++;
}
} else {
i += offset;
offset = -offset;
while (offset--) {
if (--i < 0) i = this.input.length - 1;
if (!this.input[i].visible) offset++;
}
}
return this.input[i].focus();
};
@ -727,9 +733,12 @@ Element.prototype.emit = function(type) {
Element.prototype.hide = function() {
if (this.hidden) return;
var ret = this.render(true);
this.hidden = true;
//var ret = this.render(true);
var ret = this._lastPos;
if (ret) {
this.screen.clearRegion(ret.xi, ret.xl, ret.yi, ret.yl);
}
this.emit('hide');
};
@ -756,6 +765,7 @@ Element.prototype.focus = function() {
Element.prototype.setContent = function(content) {
var ret = this.render(true);
// TODO: Maybe simply set _pcontent with _parseTags result.
// text = text.replace(/\x1b(?!\[[\d;]*m)/g, '');
this.content = this._parseTags(content || '');
this.screen.clearRegion(ret.xi, ret.xl, ret.yi, ret.yl);
};
@ -779,6 +789,14 @@ Element.prototype._parseTags = function(text) {
});
};
Element.prototype.__defineGetter__('visible', function() {
var el = this;
do {
if (el.hidden) return false;
} while (el = el.parent);
return true;
});
/**
* Positioning
*/
@ -1500,6 +1518,7 @@ function List(options) {
self.childBase = 0;
self.childOffset = self.selected;
} else {
// Is this supposed to be: self.childBase = visible - self.selected + 1; ?
self.childBase = self.selected - visible + 1;
self.childOffset = visible - 1;
}
@ -1666,7 +1685,12 @@ ScrollableText.prototype.scroll = function(offset) {
}
max = this._clines.length - 1 - (this.height - (this.border ? 2 : 0));
if (cb > max) this.childBase = cb = max;
if (max < 0) max = 0;
if (cb > max) {
this.childBase = cb = max;
diff = cb - base;
}
if (diff > 0) {
for (i = base; i < cb; i++) this.contentIndex += this._clines[i].length + 1;
@ -1690,6 +1714,10 @@ ScrollableText.prototype._recalculateIndex = function() {
this._clines = wrapContent(this.content, this.width - (this.border ? 2 : 0));
this._pcontent = this._clines.join('\n');
if (this.childBase > this._clines.length - 1) {
this.childBase = this._clines.length - 1;
}
for (var i = 0, t = 0; i < this.childBase; i++) {
t += this._clines[i].length + 1;
}
@ -1726,6 +1754,11 @@ Textbox.prototype.__proto__ = Input.prototype;
Textbox.prototype.setInput = function(callback) {
var self = this;
if (this._timeout != null) {
clearTimeout(this._timeout);
delete this._timeout;
}
this.screen.grabKeys = true;
this.focus();
@ -1740,9 +1773,9 @@ Textbox.prototype.setInput = function(callback) {
// self.screen.program.restoreCursor();
self.screen.program.hideCursor();
// Wait for global keypress event to fire.
process.nextTick(function() {
self._timeout = setTimeout(function() {
self.screen.grabKeys = false;
});
}, 1);
return err
? callback(err)
: callback(null, value);

View File

@ -139,8 +139,6 @@ var stext = new blessed.ScrollableText({
content: lorem,
fg: 'blue',
bg: 'default',
barBg: 'default',
barFg: 'blue',
border: {
type: 'ascii',
fg: 'default',