From 5035ed61eeb53f722b3ad77c63238b7c2535fdd9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Mar 2020 06:26:02 +0530 Subject: [PATCH] More typing work --- kitty/fast_data_types.pyi | 290 +++++++++++++++++++++++++++++++++++++- kitty/keys.py | 13 +- 2 files changed, 292 insertions(+), 11 deletions(-) diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 3a48a1472..97fb0572e 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1,11 +1,291 @@ from collections import namedtuple from typing import ( - Any, Callable, List, Mapping, NewType, Optional, Tuple, Union + Any, Callable, List, Dict, NewType, Optional, Tuple, Union ) from kitty.cli import Namespace GLFW_IBEAM_CURSOR: int +GLFW_KEY_UNKNOWN: int +GLFW_KEY_SPACE: int +GLFW_KEY_EXCLAM: int +GLFW_KEY_DOUBLE_QUOTE: int +GLFW_KEY_NUMBER_SIGN: int +GLFW_KEY_DOLLAR: int +GLFW_KEY_AMPERSAND: int +GLFW_KEY_APOSTROPHE: int +GLFW_KEY_PARENTHESIS_LEFT: int +GLFW_KEY_PARENTHESIS_RIGHT: int +GLFW_KEY_PLUS: int +GLFW_KEY_COMMA: int +GLFW_KEY_MINUS: int +GLFW_KEY_PERIOD: int +GLFW_KEY_SLASH: int +GLFW_KEY_0: int +GLFW_KEY_1: int +GLFW_KEY_2: int +GLFW_KEY_3: int +GLFW_KEY_4: int +GLFW_KEY_5: int +GLFW_KEY_6: int +GLFW_KEY_7: int +GLFW_KEY_8: int +GLFW_KEY_9: int +GLFW_KEY_COLON: int +GLFW_KEY_SEMICOLON: int +GLFW_KEY_LESS: int +GLFW_KEY_EQUAL: int +GLFW_KEY_GREATER: int +GLFW_KEY_AT: int +GLFW_KEY_A: int +GLFW_KEY_B: int +GLFW_KEY_C: int +GLFW_KEY_D: int +GLFW_KEY_E: int +GLFW_KEY_F: int +GLFW_KEY_G: int +GLFW_KEY_H: int +GLFW_KEY_I: int +GLFW_KEY_J: int +GLFW_KEY_K: int +GLFW_KEY_L: int +GLFW_KEY_M: int +GLFW_KEY_N: int +GLFW_KEY_O: int +GLFW_KEY_P: int +GLFW_KEY_Q: int +GLFW_KEY_R: int +GLFW_KEY_S: int +GLFW_KEY_T: int +GLFW_KEY_U: int +GLFW_KEY_V: int +GLFW_KEY_W: int +GLFW_KEY_X: int +GLFW_KEY_Y: int +GLFW_KEY_Z: int +GLFW_KEY_LEFT_BRACKET: int +GLFW_KEY_BACKSLASH: int +GLFW_KEY_RIGHT_BRACKET: int +GLFW_KEY_CIRCUMFLEX: int +GLFW_KEY_UNDERSCORE: int +GLFW_KEY_GRAVE_ACCENT: int +GLFW_KEY_WORLD_1: int +GLFW_KEY_WORLD_2: int +GLFW_KEY_PARAGRAPH: int +GLFW_KEY_MASCULINE: int +GLFW_KEY_A_GRAVE: int +GLFW_KEY_A_DIAERESIS: int +GLFW_KEY_A_RING: int +GLFW_KEY_AE: int +GLFW_KEY_C_CEDILLA: int +GLFW_KEY_E_GRAVE: int +GLFW_KEY_E_ACUTE: int +GLFW_KEY_I_GRAVE: int +GLFW_KEY_N_TILDE: int +GLFW_KEY_O_GRAVE: int +GLFW_KEY_O_DIAERESIS: int +GLFW_KEY_O_SLASH: int +GLFW_KEY_U_GRAVE: int +GLFW_KEY_U_DIAERESIS: int +GLFW_KEY_S_SHARP: int +GLFW_KEY_CYRILLIC_A: int +GLFW_KEY_CYRILLIC_BE: int +GLFW_KEY_CYRILLIC_VE: int +GLFW_KEY_CYRILLIC_GHE: int +GLFW_KEY_CYRILLIC_DE: int +GLFW_KEY_CYRILLIC_IE: int +GLFW_KEY_CYRILLIC_ZHE: int +GLFW_KEY_CYRILLIC_ZE: int +GLFW_KEY_CYRILLIC_I: int +GLFW_KEY_CYRILLIC_SHORT_I: int +GLFW_KEY_CYRILLIC_KA: int +GLFW_KEY_CYRILLIC_EL: int +GLFW_KEY_CYRILLIC_EM: int +GLFW_KEY_CYRILLIC_EN: int +GLFW_KEY_CYRILLIC_O: int +GLFW_KEY_CYRILLIC_PE: int +GLFW_KEY_CYRILLIC_ER: int +GLFW_KEY_CYRILLIC_ES: int +GLFW_KEY_CYRILLIC_TE: int +GLFW_KEY_CYRILLIC_U: int +GLFW_KEY_CYRILLIC_EF: int +GLFW_KEY_CYRILLIC_HA: int +GLFW_KEY_CYRILLIC_TSE: int +GLFW_KEY_CYRILLIC_CHE: int +GLFW_KEY_CYRILLIC_SHA: int +GLFW_KEY_CYRILLIC_SHCHA: int +GLFW_KEY_CYRILLIC_HARD_SIGN: int +GLFW_KEY_CYRILLIC_YERU: int +GLFW_KEY_CYRILLIC_SOFT_SIGN: int +GLFW_KEY_CYRILLIC_E: int +GLFW_KEY_CYRILLIC_YU: int +GLFW_KEY_CYRILLIC_YA: int +GLFW_KEY_CYRILLIC_IO: int +GLFW_KEY_LAST_PRINTABLE: int +GLFW_KEY_ESCAPE: int +GLFW_KEY_ENTER: int +GLFW_KEY_TAB: int +GLFW_KEY_BACKSPACE: int +GLFW_KEY_INSERT: int +GLFW_KEY_DELETE: int +GLFW_KEY_RIGHT: int +GLFW_KEY_LEFT: int +GLFW_KEY_DOWN: int +GLFW_KEY_UP: int +GLFW_KEY_PAGE_UP: int +GLFW_KEY_PAGE_DOWN: int +GLFW_KEY_HOME: int +GLFW_KEY_END: int +GLFW_KEY_CAPS_LOCK: int +GLFW_KEY_SCROLL_LOCK: int +GLFW_KEY_NUM_LOCK: int +GLFW_KEY_PRINT_SCREEN: int +GLFW_KEY_PAUSE: int +GLFW_KEY_F1: int +GLFW_KEY_F2: int +GLFW_KEY_F3: int +GLFW_KEY_F4: int +GLFW_KEY_F5: int +GLFW_KEY_F6: int +GLFW_KEY_F7: int +GLFW_KEY_F8: int +GLFW_KEY_F9: int +GLFW_KEY_F10: int +GLFW_KEY_F11: int +GLFW_KEY_F12: int +GLFW_KEY_F13: int +GLFW_KEY_F14: int +GLFW_KEY_F15: int +GLFW_KEY_F16: int +GLFW_KEY_F17: int +GLFW_KEY_F18: int +GLFW_KEY_F19: int +GLFW_KEY_F20: int +GLFW_KEY_F21: int +GLFW_KEY_F22: int +GLFW_KEY_F23: int +GLFW_KEY_F24: int +GLFW_KEY_F25: int +GLFW_KEY_KP_0: int +GLFW_KEY_KP_1: int +GLFW_KEY_KP_2: int +GLFW_KEY_KP_3: int +GLFW_KEY_KP_4: int +GLFW_KEY_KP_5: int +GLFW_KEY_KP_6: int +GLFW_KEY_KP_7: int +GLFW_KEY_KP_8: int +GLFW_KEY_KP_9: int +GLFW_KEY_KP_DECIMAL: int +GLFW_KEY_KP_DIVIDE: int +GLFW_KEY_KP_MULTIPLY: int +GLFW_KEY_KP_SUBTRACT: int +GLFW_KEY_KP_ADD: int +GLFW_KEY_KP_ENTER: int +GLFW_KEY_KP_EQUAL: int +GLFW_KEY_LEFT_SHIFT: int +GLFW_KEY_LEFT_CONTROL: int +GLFW_KEY_LEFT_ALT: int +GLFW_KEY_LEFT_SUPER: int +GLFW_KEY_RIGHT_SHIFT: int +GLFW_KEY_RIGHT_CONTROL: int +GLFW_KEY_RIGHT_ALT: int +GLFW_KEY_RIGHT_SUPER: int +GLFW_KEY_MENU: int +GLFW_KEY_LAST: int +GLFW_MOD_SHIFT: int +GLFW_MOD_CONTROL: int +GLFW_MOD_ALT: int +GLFW_MOD_SUPER: int +GLFW_MOD_KITTY: int +GLFW_MOUSE_BUTTON_1: int +GLFW_MOUSE_BUTTON_2: int +GLFW_MOUSE_BUTTON_3: int +GLFW_MOUSE_BUTTON_4: int +GLFW_MOUSE_BUTTON_5: int +GLFW_MOUSE_BUTTON_6: int +GLFW_MOUSE_BUTTON_7: int +GLFW_MOUSE_BUTTON_8: int +GLFW_MOUSE_BUTTON_LAST: int +GLFW_MOUSE_BUTTON_LEFT: int +GLFW_MOUSE_BUTTON_RIGHT: int +GLFW_MOUSE_BUTTON_MIDDLE: int +GLFW_JOYSTICK_1: int +GLFW_JOYSTICK_2: int +GLFW_JOYSTICK_3: int +GLFW_JOYSTICK_4: int +GLFW_JOYSTICK_5: int +GLFW_JOYSTICK_6: int +GLFW_JOYSTICK_7: int +GLFW_JOYSTICK_8: int +GLFW_JOYSTICK_9: int +GLFW_JOYSTICK_10: int +GLFW_JOYSTICK_11: int +GLFW_JOYSTICK_12: int +GLFW_JOYSTICK_13: int +GLFW_JOYSTICK_14: int +GLFW_JOYSTICK_15: int +GLFW_JOYSTICK_16: int +GLFW_JOYSTICK_LAST: int +GLFW_NOT_INITIALIZED: int +GLFW_NO_CURRENT_CONTEXT: int +GLFW_INVALID_ENUM: int +GLFW_INVALID_VALUE: int +GLFW_OUT_OF_MEMORY: int +GLFW_API_UNAVAILABLE: int +GLFW_VERSION_UNAVAILABLE: int +GLFW_PLATFORM_ERROR: int +GLFW_FORMAT_UNAVAILABLE: int +GLFW_FOCUSED: int +GLFW_ICONIFIED: int +GLFW_RESIZABLE: int +GLFW_VISIBLE: int +GLFW_DECORATED: int +GLFW_AUTO_ICONIFY: int +GLFW_FLOATING: int +GLFW_RED_BITS: int +GLFW_GREEN_BITS: int +GLFW_BLUE_BITS: int +GLFW_ALPHA_BITS: int +GLFW_DEPTH_BITS: int +GLFW_STENCIL_BITS: int +GLFW_ACCUM_RED_BITS: int +GLFW_ACCUM_GREEN_BITS: int +GLFW_ACCUM_BLUE_BITS: int +GLFW_ACCUM_ALPHA_BITS: int +GLFW_AUX_BUFFERS: int +GLFW_STEREO: int +GLFW_SAMPLES: int +GLFW_SRGB_CAPABLE: int +GLFW_REFRESH_RATE: int +GLFW_DOUBLEBUFFER: int +GLFW_CLIENT_API: int +GLFW_CONTEXT_VERSION_MAJOR: int +GLFW_CONTEXT_VERSION_MINOR: int +GLFW_CONTEXT_REVISION: int +GLFW_CONTEXT_ROBUSTNESS: int +GLFW_OPENGL_FORWARD_COMPAT: int +GLFW_OPENGL_DEBUG_CONTEXT: int +GLFW_OPENGL_PROFILE: int +GLFW_OPENGL_API: int +GLFW_OPENGL_ES_API: int +GLFW_NO_ROBUSTNESS: int +GLFW_NO_RESET_NOTIFICATION: int +GLFW_LOSE_CONTEXT_ON_RESET: int +GLFW_OPENGL_ANY_PROFILE: int +GLFW_OPENGL_CORE_PROFILE: int +GLFW_OPENGL_COMPAT_PROFILE: int +GLFW_CURSOR: int +GLFW_STICKY_KEYS: int +GLFW_STICKY_MOUSE_BUTTONS: int +GLFW_CURSOR_NORMAL: int +GLFW_CURSOR_HIDDEN: int +GLFW_CURSOR_DISABLED: int +GLFW_CONNECTED: int +GLFW_DISCONNECTED: int +GLFW_PRESS: int +GLFW_RELEASE: int +GLFW_REPEAT: int CURSOR_BEAM: int CURSOR_BLOCK: int CURSOR_UNDERLINE: int @@ -45,7 +325,7 @@ def default_color_table() -> Tuple[int, ...]: pass -FontConfigPattern = Mapping[str, Union[str, int, bool, float]] +FontConfigPattern = Dict[str, Union[str, int, bool, float]] def fc_list(spacing: int = -1, allow_bitmapped_fonts: bool = False) -> Tuple[FontConfigPattern, ...]: @@ -64,7 +344,7 @@ def fc_match( pass -def coretext_all_fonts() -> Tuple[Mapping[str, Any], ...]: +def coretext_all_fonts() -> Tuple[Dict[str, Any], ...]: pass @@ -197,7 +477,7 @@ def safe_pipe(nonblock: bool = True) -> Tuple[int, int]: pass -def patch_global_colors(spec: Mapping[str, int], configured: bool) -> None: +def patch_global_colors(spec: Dict[str, int], configured: bool) -> None: pass @@ -375,7 +655,7 @@ def set_font_data( bold: int, italic: int, bold_italic: int, num_symbol_fonts: int, symbol_maps: Tuple[Tuple[int, int, int], ...], font_sz_in_pts: float, - font_feature_settings: Mapping[str, Tuple[bytes, ...]] + font_feature_settings: Dict[str, Tuple[bytes, ...]] ): pass diff --git a/kitty/keys.py b/kitty/keys.py index 1042ea730..1586d9e94 100644 --- a/kitty/keys.py +++ b/kitty/keys.py @@ -3,6 +3,7 @@ # License: GPL v3 Copyright: 2016, Kovid Goyal import string +from typing import Dict, Tuple, Union from . import fast_data_types as defines from .key_encoding import KEY_MAP @@ -16,7 +17,7 @@ def modify_complex_key(name, amt): return modify_key_bytes(name, amt) -control_codes = { +control_codes: Dict[int, Union[bytes, Tuple[int, ...]]] = { defines.GLFW_KEY_BACKSPACE: b'\x08' } smkx_key_map = {} @@ -96,8 +97,8 @@ for f in range(13, 26): kn = 'kf{}'.format(f) smkx_key_map[kf] = key_as_bytes(kn) create_modifier_variants(defines.GLFW_KEY_MENU, b'\x1b[29~') -f = {k: k for k in '0123456789'} -f.update({ +f_ = {k: k for k in '0123456789'} +f_.update({ 'COMMA': ',', 'PERIOD': '.', 'SEMICOLON': ';', @@ -105,9 +106,9 @@ f.update({ 'MINUS': '-', 'EQUAL': '=', }) -for kf, kn in f.items(): - control_codes[getattr(defines, 'GLFW_KEY_' + kf)] = (ord(kn),) -del f, kf, kn +for kf_, kn_ in f_.items(): + control_codes[getattr(defines, 'GLFW_KEY_' + kf_)] = (ord(kn_),) +del f, f_, kf, kn, kf_, kn_ smkx_key_map[defines.GLFW_KEY_ESCAPE] = b'\033' smkx_key_map[defines.GLFW_KEY_ENTER] = b'\r'