diff --git a/lib/widget.js b/lib/widget.js index 02c9bb6..40cb793 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2303,6 +2303,13 @@ Element.prototype.parseContent = function(noTags) { return false; }; +Element.prototype.textLength = function(text) { + if (!this.options.tags && !this.options.parseTags) { + return text.length; + } + return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length; +}; + // Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`. Element.prototype._parseTags = function(text) { if (!this.parseTags) return text; @@ -7005,7 +7012,7 @@ Table.prototype.setData = function(rows) { this.rows.forEach(function(row) { row.forEach(function(cell, i) { - var clen = self._cellLength(cell); + var clen = self.textLength(cell); if (!maxes[i] || maxes[i] < clen + self.pad) { maxes[i] = clen + self.pad; } @@ -7023,7 +7030,7 @@ Table.prototype.setData = function(rows) { var isFooter = i === self.rows.length - 1; row.forEach(function(cell, i) { var width = maxes[i]; - var clen = self._cellLength(cell); + var clen = self.textLength(cell); if (i !== 0) { text += ' '; @@ -7082,13 +7089,6 @@ Table.prototype.setData = function(rows) { this.align = align; }; -Table.prototype._cellLength = function(text) { - if (!this.options.tags && !this.options.parseTags) { - return text.length; - } - return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length; -}; - Table.prototype.render = function() { var self = this; @@ -7292,7 +7292,7 @@ ListTable.prototype.setData = function(rows) { this.rows.forEach(function(row) { row.forEach(function(cell, i) { - var clen = self._cellLength(cell); + var clen = self.textLength(cell); if (!maxes[i] || maxes[i] < clen + self.pad) { maxes[i] = clen + self.pad; } @@ -7313,7 +7313,7 @@ ListTable.prototype.setData = function(rows) { var text = ''; row.forEach(function(cell, i) { var width = maxes[i]; - var clen = self._cellLength(cell); + var clen = self.textLength(cell); if (i !== 0) { text += ' '; @@ -7370,13 +7370,6 @@ ListTable.prototype.select = function(i) { return this._select(i); }; -ListTable.prototype._cellLength = function(text) { - if (!this.options.tags && !this.options.parseTags) { - return text.length; - } - return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length; -}; - ListTable.prototype.render = function() { var self = this;