add shrink option to Box.

This commit is contained in:
Christopher Jeffrey 2013-06-13 04:22:45 -05:00
parent d9a0b49bce
commit 1765d44a69
2 changed files with 11 additions and 8 deletions

View File

@ -2642,11 +2642,9 @@ exports = Program;
exports.Program = Program;
exports.Tput = Tput;
['Screen', 'Box', 'Text', 'List', 'Line', 'ProgressBar',
'ScrollableBox', 'ScrollableText', 'Textbox'].forEach(function(key) {
exports.__defineGetter__(key, function() {
return (exports._widget || (exports._widget = require('./widget')))[key];
});
exports.widget = require('./widget');
Object.keys(exports.widget).forEach(function(name) {
exports[name] = exports.widget[name];
});
module.exports = exports;

View File

@ -573,6 +573,7 @@ function Element(options) {
this.fixed = options.fixed || false;
this.align = options.align || 'left';
this.shrink = options.shrink;
this.border = options.border;
if (this.border) {
this.border.type = this.border.type || 'bg';
@ -597,11 +598,12 @@ function Element(options) {
this.content = options.content || '';
if (options.label) {
this.append(new Text({
this.append(new Box({
screen: this.screen,
content: options.label,
left: 2,
top: this.border ? 0 : -1
top: this.border ? 0 : -1,
shrink: true
}));
}
@ -1096,6 +1098,10 @@ Box.prototype.render = function(stop) {
ch = content[ci++] || ' ';
if (this.shrink && !content[ci - 1]) {
if (this.border) continue; else break;
}
// Handle escape codes.
while (ch === '\x1b') {
if (c = /^\x1b\[(?:\d+(?:;\d+)*)?m/.exec(content.substring(ci - 1))) {
@ -1414,7 +1420,6 @@ List.prototype.__proto__ = ScrollableBox.prototype;
List.prototype.add = function(item) {
var self = this;
// TODO: Use box here and get rid of text.
var item = new Box({
screen: this.screen,
parent: this,