diff options
author | Florrie <towerofnix@gmail.com> | 2020-07-15 22:08:34 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2020-07-15 22:08:34 -0300 |
commit | 3bd328e68894a7819aa26e2325d7984eaa3959e0 (patch) | |
tree | 43202cd7a0cbaa3d94a2116622f951a7a37b820a /util | |
parent | be0919ac31b1048248941ed0c290c03824732297 (diff) |
don't include ANSI escape codes in measureColumns
This allows pretty much any code based around measureColumns (e.g. buttons, labels, word-wrapping code) to handle ANSI-formatted text without any miscalculated measurements.
Diffstat (limited to 'util')
-rw-r--r-- | util/ansi.js | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/util/ansi.js b/util/ansi.js index ac511ed..f921349 100644 --- a/util/ansi.js +++ b/util/ansi.js @@ -153,7 +153,12 @@ const ansi = { }, measureColumns(text) { - // Returns the number of columns the given text takes. + // Returns the number of columns the given text takes. Accounts for escape + // codes (by not including them in the returned width). + + if (text.includes(ESC)) { + text = text.replace(new RegExp(ESC + '\\[\\??[0-9]*.', 'g'), '') + } return wcwidth(text) }, |