Fast function to replace c0 codes

This commit is contained in:
Kovid Goyal
2023-11-03 17:27:35 +05:30
parent c81ac668da
commit 23bb2e1b67
3 changed files with 88 additions and 12 deletions

View File

@@ -13,6 +13,7 @@ from kitty.fast_data_types import (
LineBuf,
expand_ansi_c_escapes,
parse_input_from_terminal,
replace_c0_codes_except_for_newline_and_space,
strip_csi,
truncate_point_for_length,
wcswidth,
@@ -37,6 +38,17 @@ def create_lbuf(*lines):
class TestDataTypes(BaseTest):
def test_replace_c0_codes(self):
def t(x: str, expected: str):
q = replace_c0_codes_except_for_newline_and_space(x)
self.ae(expected, q)
q = replace_c0_codes_except_for_newline_and_space(x.encode('utf-8'))
self.ae(expected.encode('utf-8'), q)
t('abc', 'abc')
t('a\0\x01b\x03\x04\t\rc', 'a\u2400\u2401b\u2403\u2404\u2409\u240dc')
t('a\0\x01😸\x03\x04\t\rc', 'a\u2400\u2401😸\u2403\u2404\u2409\u240dc')
def test_to_color(self):
for x in 'xxx #12 #1234 rgb:a/b'.split():
self.assertIsNone(to_color(x))