From 61548591104a3fb679d04303448eb3f154c88404 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 31 Mar 2015 00:39:59 -0700 Subject: [PATCH] cleanup Table code. fixes for Table. --- lib/widget.js | 28 ++++------------------------ test/widget-listtable.js | 6 ++++-- test/widget-table.js | 4 +++- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 00da132..f43eb8b 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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); }; diff --git a/test/widget-listtable.js b/test/widget-listtable.js index 753cc06..e56bb34 100644 --- a/test/widget-listtable.js +++ b/test/widget-listtable.js @@ -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}'; diff --git a/test/widget-table.js b/test/widget-table.js index 8cccf43..45462a6 100644 --- a/test/widget-table.js +++ b/test/widget-table.js @@ -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}';