def parse_map(val: str) -> Iterable[KeyDefinition]: parts = val.split(maxsplit=1) if len(parts) != 2: return sc, action = parts sc, action = sc.strip().strip(sequence_sep), action.strip() if not sc or not action: return is_sequence = sequence_sep in sc if is_sequence: trigger: Optional[SingleKey] = None restl: List[SingleKey] = [] for part in sc.split(sequence_sep): try: mods, is_native, key = parse_shortcut(part) except InvalidMods: return if key == 0: if mods is not None: log_error( 'Shortcut: {} has unknown key, ignoring'.format(sc)) return if trigger is None: trigger = SingleKey(mods, is_native, key) else: restl.append(SingleKey(mods, is_native, key)) rest = tuple(restl) else: try: mods, is_native, key = parse_shortcut(sc) except InvalidMods: return if key == 0: if mods is not None: log_error('Shortcut: {} has unknown key, ignoring'.format(sc)) return try: paction = parse_key_action(action) except Exception: log_error('Invalid shortcut action: {}. Ignoring.'.format(action)) else: if paction is not None: if is_sequence: if trigger is not None: yield KeyDefinition(True, paction, trigger[0], trigger[1], trigger[2], rest) else: assert key is not None yield KeyDefinition(False, paction, mods, is_native, key)
def parse_shortcut(sc: str) -> SingleKey: if sc.endswith('+') and len(sc) > 1: sc = sc[:-1] + 'plus' parts = sc.split('+') mods = 0 if len(parts) > 1: mods = parse_mods(parts[:-1], sc) or 0 if not mods: raise InvalidMods('Invalid shortcut') q = parts[-1] q = character_key_name_aliases_with_ascii_lowercase.get(q.upper(), q) is_native = False if q.startswith('0x'): try: key = int(q, 16) except Exception: key = 0 else: is_native = True else: try: key = ord(q) except Exception: uq = q.upper() uq = functional_key_name_aliases.get(uq, uq) x: Optional[int] = getattr(defines, f'GLFW_FKEY_{uq}', None) if x is None: lf = get_key_name_lookup() key = lf(q, False) or 0 is_native = key > 0 else: key = x return SingleKey(mods, is_native, key or 0)
def __init__(self, is_sequence: bool = False, trigger: SingleKey = SingleKey(), rest: Tuple[SingleKey, ...] = (), definition: str = ''): super().__init__(definition) self.is_sequence = is_sequence self.trigger = trigger self.rest = rest
def __init__(self, is_sequence: bool, action: KeyAction, mods: int, is_native: bool, key: int, rest: Tuple[SingleKey, ...] = ()): self.is_sequence = is_sequence self.action = action self.trigger = SingleKey(mods, is_native, key) self.rest = rest
def r(k: SingleKey) -> SingleKey: mods = defines.resolve_key_mods(kitty_mod, k.mods) return k._replace(mods=mods)
def __init__( self, is_sequence: bool = False, actions: Tuple[KeyAction, ...] = (), trigger: SingleKey = SingleKey(), rest: Tuple[SingleKey, ...] = (), original_definition: str = '' ): super().__init__(original_definition) self.is_sequence = is_sequence self.actions = actions self.trigger = trigger self.rest = rest
KeyDefinition(False, KeyAction('change_font_size', (True, '-', 2.0)), 1024, False, 45, ()), # decrease_font_size KeyDefinition(False, KeyAction('change_font_size', (True, '-', 2.0)), 1024, False, 57412, ()), # reset_font_size KeyDefinition(False, KeyAction('change_font_size', (True, None, 0.0)), 1024, False, 57347, ()), # open_url KeyDefinition(False, KeyAction('kitten', ('hints', )), 1024, False, 101, ()), # insert_selected_path KeyDefinition(True, KeyAction('kitten', ('hints', '--type path --program -')), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=102), )), # open_selected_path KeyDefinition(True, KeyAction('kitten', ('hints', '--type path')), 1024, False, 112, (SingleKey(mods=1, is_native=False, key=102), )), # insert_selected_line KeyDefinition(True, KeyAction('kitten', ('hints', '--type line --program -')), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=108), )), # insert_selected_word KeyDefinition(True, KeyAction('kitten', ('hints', '--type word --program -')), 1024, False, 112, (SingleKey(mods=0, is_native=False, key=119), )), # insert_selected_hash KeyDefinition(True,
return object.__setattr__(self, key, val) defaults = Options() defaults.action_alias = {} defaults.env = {} defaults.exe_search_path = {} defaults.font_features = {} defaults.kitten_alias = {} defaults.narrow_symbols = {} defaults.symbol_map = {} defaults.watcher = {} defaults.map = [ # copy_to_clipboard KeyDefinition(trigger=SingleKey(mods=1024, key=99), definition='copy_to_clipboard'), # noqa # paste_from_clipboard KeyDefinition(trigger=SingleKey(mods=1024, key=118), definition='paste_from_clipboard'), # noqa # paste_from_selection KeyDefinition(trigger=SingleKey(mods=1024, key=115), definition='paste_from_selection'), # noqa # paste_from_selection KeyDefinition(trigger=SingleKey(mods=1, key=57348), definition='paste_from_selection'), # noqa # pass_selection_to_program KeyDefinition(trigger=SingleKey(mods=1024, key=111), definition='pass_selection_to_program'), # noqa # scroll_line_up KeyDefinition(trigger=SingleKey(mods=1024, key=57352),
self.color_table[k] = int(val) return object.__setattr__(self, key, val) defaults = Options() defaults.action_alias = {} defaults.env = {} defaults.exe_search_path = {} defaults.font_features = {} defaults.kitten_alias = {} defaults.symbol_map = {} defaults.watcher = {} defaults.map = [ # copy_to_clipboard KeyDefinition(trigger=SingleKey(mods=1024, key=99), definition='copy_to_clipboard'), # noqa # paste_from_clipboard KeyDefinition(trigger=SingleKey(mods=1024, key=118), definition='paste_from_clipboard'), # noqa # paste_from_selection KeyDefinition(trigger=SingleKey(mods=1024, key=115), definition='paste_from_selection'), # noqa # paste_from_selection KeyDefinition(trigger=SingleKey(mods=1, key=57348), definition='paste_from_selection'), # noqa # pass_selection_to_program KeyDefinition(trigger=SingleKey(mods=1024, key=111), definition='pass_selection_to_program'), # noqa # scroll_line_up KeyDefinition(trigger=SingleKey(mods=1024, key=57352), definition='scroll_line_up'), # noqa # scroll_line_up KeyDefinition(trigger=SingleKey(mods=1024, key=107), definition='scroll_line_up'), # noqa # scroll_line_down KeyDefinition(trigger=SingleKey(mods=1024, key=57353), definition='scroll_line_down'), # noqa # scroll_line_down