cleanup Table code. fixes for Table.

This commit is contained in:
Christopher Jeffrey 2015-03-31 00:39:59 -07:00
parent b067845242
commit 6154859110
3 changed files with 11 additions and 27 deletions

View File

@ -6849,8 +6849,7 @@ Table.prototype.setData = function(rows) {
, line = ''
, align = this.align;
var sborder = generateTags(this.style.border)
, sheader = generateTags(this.style.header)
var sheader = generateTags(this.style.header)
, scell = generateTags(this.style.cell);
this.rows = rows || [];
@ -6870,16 +6869,6 @@ Table.prototype.setData = function(rows) {
this._maxes = maxes;
// maxes.forEach(function(width, i) {
// if (i !== 0) {
// line += '\u253c'; // '┼'
// }
// for (var i = 0; i < width; i++) {
// line += '\u2500'; // '─'
// }
// });
// line = sborder.open + line + sborder.close;
this.rows.forEach(function(row, i) {
var isHeader = i === 0;
var isFooter = i === self.rows.length - 1;
@ -6888,7 +6877,6 @@ Table.prototype.setData = function(rows) {
var clen = self._cellLength(cell);
if (i !== 0) {
// text += sborder.open + '\u2502' + sborder.close; // '│'
text += ' ';
}
@ -6907,7 +6895,6 @@ Table.prototype.setData = function(rows) {
if (clen > width) {
if (align === 'center') {
// cell = cell.slice(0, -1);
cell = cell.substring(1);
clen--;
} else if (align === 'left') {
@ -6919,7 +6906,6 @@ Table.prototype.setData = function(rows) {
}
}
// XXX Workaround
if (!self.options.tags && !self.options.parseTags) {
cell = helpers.escape(cell);
}
@ -6934,7 +6920,6 @@ Table.prototype.setData = function(rows) {
});
text += '\n';
if (!isFooter) {
// text += line + '\n';
text += '\n';
}
});
@ -7025,7 +7010,7 @@ Table.prototype.render = function() {
lines[yi + ry][xi + 0][0] = battr;
lines[yi + ry][xi + 0][1] = '\u251c'; // '├'
}
} else if (i === self.rows.length - 1) {
} else if (i === self._maxes.length - 1) {
// right side
if (ry === 0) {
// top
@ -7082,10 +7067,6 @@ Table.prototype.render = function() {
}
rx++;
}
// if (ry % 2 === 0 && i !== self._maxes.length - 1) {
// lines[yi + ry][xi + rx][0] = battr;
// lines[yi + ry][xi + rx][1] = '\u253c'; // '┼'
// }
rx++;
});
}
@ -7136,7 +7117,6 @@ function ListTable(options) {
if (!self.screen.autoPadding) {
self._header.rtop = 1 + self.childBase;
}
// self.screen.render();
});
this.pad = options.pad != null
@ -7235,8 +7215,8 @@ ListTable.prototype.select = function(i) {
if (i === 0) {
i = 1;
}
if (i <= 1) {
this.setScroll(0);
if (i <= this.childBase) {
this.setScroll(this.childBase - 1);
}
return this._select(i);
};

View File

@ -15,7 +15,7 @@ var table = blessed.listtable({
align: 'center',
tags: true,
keys: true,
height: 4,
height: 5,
vi: true,
mouse: true,
style: {
@ -38,7 +38,9 @@ var table = blessed.listtable({
var data = [
[ 'Animals', 'Foods', 'Times' ],
[ 'Elephant', 'Apple', '1:00am' ],
[ 'Bird', 'Orange', '2:15pm' ]
[ 'Bird', 'Orange', '2:15pm' ],
[ 'T-Rex', 'Taco', '8:45am' ],
[ 'Mouse', 'Cheese', '9:05am' ]
];
data[1][0] = '{red-fg}' + data[1][0] + '{/red-fg}';

View File

@ -31,7 +31,9 @@ var table = blessed.table({
var data = [
[ 'Animals', 'Foods', 'Times' ],
[ 'Elephant', 'Apple', '1:00am' ],
[ 'Bird', 'Orange', '2:15pm' ]
[ 'Bird', 'Orange', '2:15pm' ],
[ 'T-Rex', 'Taco', '8:45am' ],
[ 'Mouse', 'Cheese', '9:05am' ]
];
data[1][0] = '{red-fg}' + data[1][0] + '{/red-fg}';