add table cell text alignment.

This commit is contained in:
Christopher Jeffrey 2015-03-30 05:16:22 -07:00
parent bc94be742e
commit cbc94254b4
2 changed files with 19 additions and 4 deletions

View File

@ -6804,6 +6804,9 @@ function Table(options) {
? options.pad
: 2;
this.__align = options.align || 'center';
delete this.align;
this.setData(options.rows || options.data);
}
@ -6856,17 +6859,28 @@ Table.prototype.setData = function(rows) {
var width = maxes[i];
if (i !== 0) {
// text += '\u2502'; // '│'
text += generateTags(self.style.border, '\u2502'); // '│'
}
while (self._cellLength(cell) < width) {
cell = ' ' + cell + ' ';
if (self.__align === 'center') {
cell = ' ' + cell + ' ';
} else if (self.__align === 'left') {
cell = cell + ' ';
} else if (self.__align === 'right') {
cell = ' ' + cell;
}
}
if (self._cellLength(cell) > width) {
// cell = cell.slice(0, -1);
cell = cell.substring(1);
if (self.__align === 'center') {
// cell = cell.slice(0, -1);
cell = cell.substring(1);
} else if (self.__align === 'left') {
cell = cell.slice(0, -1);
} else if (self.__align === 'right') {
cell = cell.substring(1);
}
}
// XXX Workaround

View File

@ -12,6 +12,7 @@ var table = blessed.table({
left: 'center',
data: null,
border: 'line',
align: 'center',
style: {
border: {
fg: 'red'