mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-11 03:25:45 +00:00
textLength improvement.
This commit is contained in:
parent
7a3525be77
commit
51c3d88a69
@ -487,6 +487,7 @@ parameter must be a string.
|
||||
- __getLines()__ - an array containing the content lines.
|
||||
- __getScreenLines()__ - an array containing the lines as they are displayed on
|
||||
the screen.
|
||||
- __textLength(text)__ - get a string's real length, taking into account tags.
|
||||
|
||||
|
||||
#### Box (from Element)
|
||||
|
@ -2307,7 +2307,10 @@ Element.prototype.textLength = function(text) {
|
||||
if (!this.options.tags && !this.options.parseTags) {
|
||||
return text.length;
|
||||
}
|
||||
return text.replace(/{(\/?)([\w\-,;!#]*)}/g, '').length;
|
||||
return text
|
||||
.replace(/{(\/?)([\w\-,;!#]*)}/g, '')
|
||||
.replace(/\x1b\[[\d;]*m/g, '')
|
||||
.length;
|
||||
};
|
||||
|
||||
// Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user