Make wcswidth ignore more escape codes

Needed to ignore OSC 8 hyperlinks since we will
eventually have to send those with SGR formatting to the hints
kitten.
This commit is contained in:
Kovid Goyal
2020-09-17 20:16:17 +05:30
parent b06f4f2574
commit 6461dccbdc
2 changed files with 49 additions and 5 deletions

View File

@@ -354,9 +354,11 @@ class TestDataTypes(BaseTest):
def test_utils(self):
def w(x):
return wcwidth(ord(x))
self.ae(wcswidth('a\033[2mb'), 2)
self.ae(wcswidth('\033a\033[2mb'), 2)
self.ae(wcswidth('a\033]8;id=moo;https://foo\033\\a'), 2)
self.ae(tuple(map(w, 'a1\0コニチ ✔')), (1, 1, 0, 2, 2, 2, 1, 1))
self.ae(wcswidth('\u2716\u2716\ufe0f\U0001f337'), 5)
self.ae(wcswidth('\033a\033[2mb'), 2)
self.ae(wcswidth('\u25b6\ufe0f'), 2)
self.ae(wcswidth('\U0001f610\ufe0e'), 1)
self.ae(wcswidth('\U0001f1e6a'), 3)