numerous improvements.
This commit is contained in:
parent
f59f7dc0e0
commit
3d52833fa3
|
@ -27,6 +27,7 @@ function Node(options) {
|
||||||
|| (function(){throw new Error('No active screen.')})();
|
|| (function(){throw new Error('No active screen.')})();
|
||||||
this.parent = options.parent || null; // this.screen;
|
this.parent = options.parent || null; // this.screen;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
this.$ = this._ = this.data = {};
|
||||||
|
|
||||||
(options.children || []).forEach(this.append.bind(this));
|
(options.children || []).forEach(this.append.bind(this));
|
||||||
|
|
||||||
|
@ -194,7 +195,7 @@ Screen.prototype._listenMouse = function(el) {
|
||||||
|
|
||||||
for (; i < self.clickable.length; i++) {
|
for (; i < self.clickable.length; i++) {
|
||||||
el = self.clickable[i];
|
el = self.clickable[i];
|
||||||
if (el.hidden) continue;
|
if (!el.visible) continue;
|
||||||
|
|
||||||
// Get the true coordinates.
|
// Get the true coordinates.
|
||||||
//ret = el.render(true);
|
//ret = el.render(true);
|
||||||
|
@ -550,18 +551,23 @@ Screen.prototype._reduceColor = function(col) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Screen.prototype.focus = function(offset) {
|
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);
|
var i = this.input.indexOf(this.focused);
|
||||||
if (!~i) return;
|
if (!~i) return;
|
||||||
if (!this.input[i + offset]) {
|
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
while (offset--) if (++i > this.input.length - 1) i = 0;
|
while (offset--) {
|
||||||
} else {
|
if (++i > this.input.length - 1) i = 0;
|
||||||
offset = -offset;
|
if (!this.input[i].visible) offset++;
|
||||||
while (offset--) if (--i < 0) i = this.input.length - 1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} 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();
|
return this.input[i].focus();
|
||||||
};
|
};
|
||||||
|
@ -727,9 +733,12 @@ Element.prototype.emit = function(type) {
|
||||||
|
|
||||||
Element.prototype.hide = function() {
|
Element.prototype.hide = function() {
|
||||||
if (this.hidden) return;
|
if (this.hidden) return;
|
||||||
var ret = this.render(true);
|
|
||||||
this.hidden = 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.screen.clearRegion(ret.xi, ret.xl, ret.yi, ret.yl);
|
||||||
|
}
|
||||||
this.emit('hide');
|
this.emit('hide');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -756,6 +765,7 @@ Element.prototype.focus = function() {
|
||||||
Element.prototype.setContent = function(content) {
|
Element.prototype.setContent = function(content) {
|
||||||
var ret = this.render(true);
|
var ret = this.render(true);
|
||||||
// TODO: Maybe simply set _pcontent with _parseTags result.
|
// TODO: Maybe simply set _pcontent with _parseTags result.
|
||||||
|
// text = text.replace(/\x1b(?!\[[\d;]*m)/g, '');
|
||||||
this.content = this._parseTags(content || '');
|
this.content = this._parseTags(content || '');
|
||||||
this.screen.clearRegion(ret.xi, ret.xl, ret.yi, ret.yl);
|
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
|
* Positioning
|
||||||
*/
|
*/
|
||||||
|
@ -1500,6 +1518,7 @@ function List(options) {
|
||||||
self.childBase = 0;
|
self.childBase = 0;
|
||||||
self.childOffset = self.selected;
|
self.childOffset = self.selected;
|
||||||
} else {
|
} else {
|
||||||
|
// Is this supposed to be: self.childBase = visible - self.selected + 1; ?
|
||||||
self.childBase = self.selected - visible + 1;
|
self.childBase = self.selected - visible + 1;
|
||||||
self.childOffset = 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));
|
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) {
|
if (diff > 0) {
|
||||||
for (i = base; i < cb; i++) this.contentIndex += this._clines[i].length + 1;
|
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._clines = wrapContent(this.content, this.width - (this.border ? 2 : 0));
|
||||||
this._pcontent = this._clines.join('\n');
|
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++) {
|
for (var i = 0, t = 0; i < this.childBase; i++) {
|
||||||
t += this._clines[i].length + 1;
|
t += this._clines[i].length + 1;
|
||||||
}
|
}
|
||||||
|
@ -1726,6 +1754,11 @@ Textbox.prototype.__proto__ = Input.prototype;
|
||||||
Textbox.prototype.setInput = function(callback) {
|
Textbox.prototype.setInput = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
if (this._timeout != null) {
|
||||||
|
clearTimeout(this._timeout);
|
||||||
|
delete this._timeout;
|
||||||
|
}
|
||||||
|
|
||||||
this.screen.grabKeys = true;
|
this.screen.grabKeys = true;
|
||||||
|
|
||||||
this.focus();
|
this.focus();
|
||||||
|
@ -1740,9 +1773,9 @@ Textbox.prototype.setInput = function(callback) {
|
||||||
// self.screen.program.restoreCursor();
|
// self.screen.program.restoreCursor();
|
||||||
self.screen.program.hideCursor();
|
self.screen.program.hideCursor();
|
||||||
// Wait for global keypress event to fire.
|
// Wait for global keypress event to fire.
|
||||||
process.nextTick(function() {
|
self._timeout = setTimeout(function() {
|
||||||
self.screen.grabKeys = false;
|
self.screen.grabKeys = false;
|
||||||
});
|
}, 1);
|
||||||
return err
|
return err
|
||||||
? callback(err)
|
? callback(err)
|
||||||
: callback(null, value);
|
: callback(null, value);
|
||||||
|
|
|
@ -139,8 +139,6 @@ var stext = new blessed.ScrollableText({
|
||||||
content: lorem,
|
content: lorem,
|
||||||
fg: 'blue',
|
fg: 'blue',
|
||||||
bg: 'default',
|
bg: 'default',
|
||||||
barBg: 'default',
|
|
||||||
barFg: 'blue',
|
|
||||||
border: {
|
border: {
|
||||||
type: 'ascii',
|
type: 'ascii',
|
||||||
fg: 'default',
|
fg: 'default',
|
||||||
|
|
Loading…
Reference in New Issue