From 1bf911a81b5fd9243b6289f09219e5b258aa3e47 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 3 Mar 2023 14:39:38 +0530 Subject: [PATCH] Generate the rowcol diacrticis for Go as well --- docs/graphics-protocol.rst | 2 +- gen-wcwidth.py | 15 ++++++++------- tools/utils/images/rowcolumn_diacritics.go | 8 ++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 tools/utils/images/rowcolumn_diacritics.go diff --git a/docs/graphics-protocol.rst b/docs/graphics-protocol.rst index 5ee16925c..33bce9bdf 100644 --- a/docs/graphics-protocol.rst +++ b/docs/graphics-protocol.rst @@ -532,7 +532,7 @@ By using only the foreground color for image ID you are limited to either 8-bit mode or 24-bit IDs in true color mode. Since IDs are in a global namespace there can easily be collisions. If you need more bits for the image ID, you can specify the most significant byte via a third diacritic. For -example, this is the placeholder for the image ID ``738197504 = 42 + (2 << 24)``: +example, this is the placeholder for the image ID ``33554474 = 42 + (2 << 24)``: .. code-block:: sh diff --git a/gen-wcwidth.py b/gen-wcwidth.py index 83f6fbc86..9743efd36 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -532,17 +532,22 @@ def gen_wcwidth() -> None: def gen_rowcolumn_diacritics() -> None: # codes of all row/column diacritics codes = [] - with open("./rowcolumn-diacritics.txt", "r") as file: + with open("./rowcolumn-diacritics.txt") as file: for line in file.readlines(): if line.startswith('#'): continue code = int(line.split(";")[0], 16) codes.append(code) - with create_header('kitty/rowcolumn-diacritics.c') as p: + go_file = 'tools/utils/images/rowcolumn_diacritics.go' + with create_header('kitty/rowcolumn-diacritics.c') as p, create_header(go_file, include_data_types=False) as g: p('#include "unicode-data.h"') p('int diacritic_to_num(char_type code) {') p('\tswitch (code) {') + g('package images') + g(f'var NumberToDiacritic = [{len(codes)}]rune''{') + g(', '.join(f'0x{x:x}' for x in codes) + ',') + g('}') range_start_num = 1 range_start = 0 @@ -568,11 +573,7 @@ def gen_rowcolumn_diacritics() -> None: p('\t}') p('\treturn 0;') p('}') - - with open('kittens/icat/rowcolumn_diacritics.py', 'w') as f: - f.write('# generated by gen-wcwidth.py, do not edit\n\n') - strings_utf8 = ', '.join(repr(chr(c).encode('utf-8')) for c in codes) - f.write("rowcolumn_diacritics_utf8 = ({}) # noqa\n".format(strings_utf8)) + subprocess.check_call(['gofmt', '-w', '-s', go_file]) parse_ucd() diff --git a/tools/utils/images/rowcolumn_diacritics.go b/tools/utils/images/rowcolumn_diacritics.go new file mode 100644 index 000000000..2ad11375f --- /dev/null +++ b/tools/utils/images/rowcolumn_diacritics.go @@ -0,0 +1,8 @@ +// Unicode data, built from the Unicode Standard 15.0.0 +// Code generated by gen-wcwidth.py, DO NOT EDIT. + +package images + +var NumberToDiacritic = [297]rune{ + 0x305, 0x30d, 0x30e, 0x310, 0x312, 0x33d, 0x33e, 0x33f, 0x346, 0x34a, 0x34b, 0x34c, 0x350, 0x351, 0x352, 0x357, 0x35b, 0x363, 0x364, 0x365, 0x366, 0x367, 0x368, 0x369, 0x36a, 0x36b, 0x36c, 0x36d, 0x36e, 0x36f, 0x483, 0x484, 0x485, 0x486, 0x487, 0x592, 0x593, 0x594, 0x595, 0x597, 0x598, 0x599, 0x59c, 0x59d, 0x59e, 0x59f, 0x5a0, 0x5a1, 0x5a8, 0x5a9, 0x5ab, 0x5ac, 0x5af, 0x5c4, 0x610, 0x611, 0x612, 0x613, 0x614, 0x615, 0x616, 0x617, 0x657, 0x658, 0x659, 0x65a, 0x65b, 0x65d, 0x65e, 0x6d6, 0x6d7, 0x6d8, 0x6d9, 0x6da, 0x6db, 0x6dc, 0x6df, 0x6e0, 0x6e1, 0x6e2, 0x6e4, 0x6e7, 0x6e8, 0x6eb, 0x6ec, 0x730, 0x732, 0x733, 0x735, 0x736, 0x73a, 0x73d, 0x73f, 0x740, 0x741, 0x743, 0x745, 0x747, 0x749, 0x74a, 0x7eb, 0x7ec, 0x7ed, 0x7ee, 0x7ef, 0x7f0, 0x7f1, 0x7f3, 0x816, 0x817, 0x818, 0x819, 0x81b, 0x81c, 0x81d, 0x81e, 0x81f, 0x820, 0x821, 0x822, 0x823, 0x825, 0x826, 0x827, 0x829, 0x82a, 0x82b, 0x82c, 0x82d, 0x951, 0x953, 0x954, 0xf82, 0xf83, 0xf86, 0xf87, 0x135d, 0x135e, 0x135f, 0x17dd, 0x193a, 0x1a17, 0x1a75, 0x1a76, 0x1a77, 0x1a78, 0x1a79, 0x1a7a, 0x1a7b, 0x1a7c, 0x1b6b, 0x1b6d, 0x1b6e, 0x1b6f, 0x1b70, 0x1b71, 0x1b72, 0x1b73, 0x1cd0, 0x1cd1, 0x1cd2, 0x1cda, 0x1cdb, 0x1ce0, 0x1dc0, 0x1dc1, 0x1dc3, 0x1dc4, 0x1dc5, 0x1dc6, 0x1dc7, 0x1dc8, 0x1dc9, 0x1dcb, 0x1dcc, 0x1dd1, 0x1dd2, 0x1dd3, 0x1dd4, 0x1dd5, 0x1dd6, 0x1dd7, 0x1dd8, 0x1dd9, 0x1dda, 0x1ddb, 0x1ddc, 0x1ddd, 0x1dde, 0x1ddf, 0x1de0, 0x1de1, 0x1de2, 0x1de3, 0x1de4, 0x1de5, 0x1de6, 0x1dfe, 0x20d0, 0x20d1, 0x20d4, 0x20d5, 0x20d6, 0x20d7, 0x20db, 0x20dc, 0x20e1, 0x20e7, 0x20e9, 0x20f0, 0x2cef, 0x2cf0, 0x2cf1, 0x2de0, 0x2de1, 0x2de2, 0x2de3, 0x2de4, 0x2de5, 0x2de6, 0x2de7, 0x2de8, 0x2de9, 0x2dea, 0x2deb, 0x2dec, 0x2ded, 0x2dee, 0x2def, 0x2df0, 0x2df1, 0x2df2, 0x2df3, 0x2df4, 0x2df5, 0x2df6, 0x2df7, 0x2df8, 0x2df9, 0x2dfa, 0x2dfb, 0x2dfc, 0x2dfd, 0x2dfe, 0x2dff, 0xa66f, 0xa67c, 0xa67d, 0xa6f0, 0xa6f1, 0xa8e0, 0xa8e1, 0xa8e2, 0xa8e3, 0xa8e4, 0xa8e5, 0xa8e6, 0xa8e7, 0xa8e8, 0xa8e9, 0xa8ea, 0xa8eb, 0xa8ec, 0xa8ed, 0xa8ee, 0xa8ef, 0xa8f0, 0xa8f1, 0xaab0, 0xaab2, 0xaab3, 0xaab7, 0xaab8, 0xaabe, 0xaabf, 0xaac1, 0xfe20, 0xfe21, 0xfe22, 0xfe23, 0xfe24, 0xfe25, 0xfe26, 0x10a0f, 0x10a38, 0x1d185, 0x1d186, 0x1d187, 0x1d188, 0x1d189, 0x1d1aa, 0x1d1ab, 0x1d1ac, 0x1d1ad, 0x1d242, 0x1d243, 0x1d244, +}