From e5e8cc72c6432a920ea1f89cfbfe29570a915c86 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Nov 2022 20:11:50 +0530 Subject: [PATCH] Make the Unicode database version used available --- gen-wcwidth.py | 13 +++++++++++++ kittens/unicode_input/names.h | 2 +- kitty/data-types.c | 1 + kitty/emoji.h | 2 +- kitty/fast_data_types.pyi | 1 + kitty/unicode-data.c | 2 +- kitty/wcswidth.c | 5 +++++ kitty/wcswidth.h | 1 + kitty/wcwidth-std.h | 5 ++++- tools/wcswidth/std.go | 2 ++ 10 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gen-wcwidth.py b/gen-wcwidth.py index b0d9d7594..7e64e9a4f 100755 --- a/gen-wcwidth.py +++ b/gen-wcwidth.py @@ -45,6 +45,14 @@ def get_data(fname: str, folder: str = 'UCD') -> Iterable[str]: yield line +def unicode_version(): + for line in get_data("ReadMe.txt"): + m = re.search(r'Version\s+(\d+)\.(\d+)\.(\d+)', line) + if m is not None: + return int(m.group(1)), int(m.group(2)), int(m.group(3)) + raise ValueError('Could not find Unicode Version') + + # Map of class names to set of codepoints in class class_maps: Dict[str, Set[int]] = {} all_symbols: Set[int] = set() @@ -586,6 +594,11 @@ def gen_wcwidth() -> None: gop('\t}') p('\treturn true;\n}') gop('\n}') + uv = unicode_version() + p(f'#define UNICODE_MAJOR_VERSION {uv[0]}') + p(f'#define UNICODE_MINOR_VERSION {uv[1]}') + p(f'#define UNICODE_PATCH_VERSION {uv[2]}') + gop('var UnicodeDatabaseVersion [3]int = [3]int{' f'{uv[0]}, {uv[1]}, {uv[2]}' + '}') subprocess.check_call(['gofmt', '-w', '-s', gof.name]) diff --git a/kittens/unicode_input/names.h b/kittens/unicode_input/names.h index f3a89b8da..c406c1f12 100644 --- a/kittens/unicode_input/names.h +++ b/kittens/unicode_input/names.h @@ -1,4 +1,4 @@ -// unicode data, built from the unicode standard on: 2022-09-30 +// unicode data, built from the unicode standard on: 2022-11-17 // see gen-wcwidth.py #pragma once #include "data-types.h" diff --git a/kitty/data-types.c b/kitty/data-types.c index 4f4fc79e4..351f443ab 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -221,6 +221,7 @@ static PyMethodDef module_methods[] = { {"get_docs_ref_map", (PyCFunction)get_docs_ref_map, METH_NOARGS, ""}, {"getpeereid", (PyCFunction)py_getpeereid, METH_VARARGS, ""}, {"wcswidth", (PyCFunction)wcswidth_std, METH_O, ""}, + {"unicode_database_version", (PyCFunction)unicode_database_version, METH_NOARGS, ""}, {"open_tty", open_tty, METH_VARARGS, ""}, {"normal_tty", normal_tty, METH_VARARGS, ""}, {"raw_tty", raw_tty, METH_VARARGS, ""}, diff --git a/kitty/emoji.h b/kitty/emoji.h index 4cd38afe8..8144ef494 100644 --- a/kitty/emoji.h +++ b/kitty/emoji.h @@ -1,4 +1,4 @@ -// unicode data, built from the unicode standard on: 2022-09-30 +// unicode data, built from the unicode standard on: 2022-11-17 // see gen-wcwidth.py #pragma once #include "data-types.h" diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 9ea11708c..031aa3fa6 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1492,3 +1492,4 @@ def set_clipboard_data_types(ct: int, mime_types: Tuple[str, ...]) -> None: ... def get_clipboard_mime(ct: int, mime: Optional[str], callback: Callable[[bytes], None]) -> None: ... def run_with_activation_token(func: Callable[[str], None]) -> None: ... def make_x11_window_a_dock_window(x11_window_id: int, strut: Tuple[int, int, int, int, int, int, int, int, int, int, int, int]) -> None: ... +def unicode_database_version() -> Tuple[int, int, int]: ... diff --git a/kitty/unicode-data.c b/kitty/unicode-data.c index 8233d6d54..dbc0db707 100644 --- a/kitty/unicode-data.c +++ b/kitty/unicode-data.c @@ -1,4 +1,4 @@ -// unicode data, built from the unicode standard on: 2022-09-30 +// unicode data, built from the unicode standard on: 2022-11-17 // see gen-wcwidth.py #include "data-types.h" diff --git a/kitty/wcswidth.c b/kitty/wcswidth.c index f75915dfb..fd3b0f75f 100644 --- a/kitty/wcswidth.c +++ b/kitty/wcswidth.c @@ -142,3 +142,8 @@ wcswidth_std(PyObject UNUSED *self, PyObject *str) { } return PyLong_FromSize_t(ans); } + +PyObject* +unicode_database_version(PyObject *self UNUSED, PyObject *args UNUSED) { + return Py_BuildValue("iii", UNICODE_MAJOR_VERSION, UNICODE_MINOR_VERSION, UNICODE_PATCH_VERSION); +} diff --git a/kitty/wcswidth.h b/kitty/wcswidth.h index 016574daa..1716a5f90 100644 --- a/kitty/wcswidth.h +++ b/kitty/wcswidth.h @@ -20,4 +20,5 @@ typedef struct { void initialize_wcs_state(WCSState *state); int wcswidth_step(WCSState *state, const char_type ch); PyObject * wcswidth_std(PyObject UNUSED *self, PyObject *str); +PyObject * unicode_database_version(PyObject UNUSED *self, PyObject *str); size_t wcswidth_string(const char_type *s); diff --git a/kitty/wcwidth-std.h b/kitty/wcwidth-std.h index 25b3f77b3..958706ccf 100644 --- a/kitty/wcwidth-std.h +++ b/kitty/wcwidth-std.h @@ -1,4 +1,4 @@ -// unicode data, built from the unicode standard on: 2022-09-30 +// unicode data, built from the unicode standard on: 2022-11-17 // see gen-wcwidth.py #pragma once #include "data-types.h" @@ -3250,5 +3250,8 @@ is_emoji_presentation_base(uint32_t code) { } return true; } +#define UNICODE_MAJOR_VERSION 15 +#define UNICODE_MINOR_VERSION 0 +#define UNICODE_PATCH_VERSION 0 END_ALLOW_CASE_RANGE diff --git a/tools/wcswidth/std.go b/tools/wcswidth/std.go index 1343a7457..16d6e89c4 100644 --- a/tools/wcswidth/std.go +++ b/tools/wcswidth/std.go @@ -3242,3 +3242,5 @@ func IsEmojiPresentationBase(code rune) bool { } } + +var UnicodeDatabaseVersion [3]int = [3]int{15, 0, 0}