Пример #1
0
def parse_key_action(action: str, action_type: str = 'map') -> KeyAction:
    parts = action.strip().split(maxsplit=1)
    func = parts[0]
    if len(parts) == 1:
        return KeyAction(func, ())
    rest = parts[1]
    parser = func_with_args.get(func)
    if parser is None:
        raise KeyError(f'Unknown action: {func}')
    func, args = parser(func, rest)
    return KeyAction(func, tuple(args))
Пример #2
0
def parse_key_action(action: str, action_type: str = 'map') -> Optional[KeyAction]:
    parts = action.strip().split(maxsplit=1)
    func = parts[0]
    if len(parts) == 1:
        return KeyAction(func, ())
    rest = parts[1]
    parser = args_funcs.get(func)
    if parser is not None:
        try:
            func, args = parser(func, rest)
        except Exception as err:
            log_error(f'Ignoring invalid {action_type} action: {action} with err: {err}')
        else:
            return KeyAction(func, tuple(args))
    else:
        log_error(f'Ignoring unknown {action_type} action: {action}')
    return None
Пример #3
0
            if q.isdigit():
                k = int(q)
                if 0 <= k <= 255:
                    self.color_table[k] = int(val)
                    return
        object.__setattr__(self, key, val)


defaults = Options()
defaults.env = {}
defaults.font_features = {}
defaults.kitten_alias = {}
defaults.symbol_map = {}
defaults.map = [
    # copy_to_clipboard
    KeyDefinition(False, KeyAction('copy_to_clipboard'), 1024, False, 99, ()),
    # paste_from_clipboard
    KeyDefinition(False, KeyAction('paste_from_clipboard'), 1024, False, 118,
                  ()),
    # paste_from_selection
    KeyDefinition(False, KeyAction('paste_from_selection'), 1024, False, 115,
                  ()),
    # paste_from_selection
    KeyDefinition(False, KeyAction('paste_from_selection'), 1, False, 57348,
                  ()),
    # pass_selection_to_program
    KeyDefinition(False, KeyAction('pass_selection_to_program'), 1024, False,
                  111, ()),
    # scroll_line_up
    KeyDefinition(False, KeyAction('scroll_line_up'), 1024, False, 57352, ()),
    # scroll_line_up
Пример #4
0
            setattr(ans, name, val)
        return ans

    def __getitem__(self, key: typing.Union[int, str]) -> typing.Any:
        k = option_names[key] if isinstance(key, int) else key
        try:
            return getattr(self, k)
        except AttributeError:
            pass
        raise KeyError(f"No option named: {k}")


defaults = Options()
defaults.map = [
    # quit
    (ParsedShortcut(mods=0, key_name='q'), KeyAction('quit')),
    # quit
    (ParsedShortcut(mods=0, key_name='ESCAPE'), KeyAction('quit')),
    # scroll_down
    (ParsedShortcut(mods=0, key_name='j'), KeyAction('scroll_by', (1, ))),
    # scroll_down
    (ParsedShortcut(mods=0, key_name='DOWN'), KeyAction('scroll_by', (1, ))),
    # scroll_up
    (ParsedShortcut(mods=0, key_name='k'), KeyAction('scroll_by', (-1, ))),
    # scroll_up
    (ParsedShortcut(mods=0, key_name='UP'), KeyAction('scroll_by', (-1, ))),
    # scroll_top
    (ParsedShortcut(mods=0,
                    key_name='HOME'), KeyAction('scroll_to', ('start', ))),
    # scroll_bottom
    (ParsedShortcut(mods=0, key_name='END'), KeyAction('scroll_to',