Ejemplo n.º 1
0
def handle_result(args, result, target_window_id, boss):
    w = boss.window_id_map.get(target_window_id)
    tab = boss.active_tab

    if w is None:
        return

    if len(args) > 4:
        if not re.search(args[4], w.title):
            boss.active_tab.neighboring_window(args[2])
            return
    else:
        # check the first word of the first foreground process
        foreground_process = w.child.foreground_processes[0]['cmdline'][0]
        if not re.search("n?vim", foreground_process, re.I):
            boss.active_tab.neighboring_window(args[2])
            return

    mods, key, is_text = ku.parse_kittens_shortcut(args[3])

    extended = w.screen.extended_keyboard

    for action in actions(extended):
        sequence = (
            ('\x1b_{}\x1b\\' if extended else '{}')
            .format(
                keys.key_to_bytes(
                    getattr(keys.defines, 'GLFW_KEY_{}'.format(key.upper())),
                    w.screen.cursor_key_mode, extended, convert_mods(mods), action)
                .decode('ascii')))
        print(repr(sequence))
        w.write_to_child(sequence)
Ejemplo n.º 2
0
def handle_result(args, answer, target_window_id, boss):
    _kitten = args[0]
    action_if_tabs = ' '.join(args[1:-1])
    if_no_tabs = args[-1]

    tm = boss.active_tab_manager
    if tm is None:
        return

    if len(tm.tabs) > 1:
        boss.dispatch_action(parse_key_action(action_if_tabs))
        return

    w = boss.window_id_map.get(target_window_id)
    mods, key, is_text = parse_kittens_shortcut(if_no_tabs)
    if is_text:
        w.send_text(key)
        return

    extended = w.screen.extended_keyboard
    for action in _actions(extended):
        sequence = (('\x1b_{}\x1b\\' if extended else '{}').format(
            keys.key_to_bytes(getattr(keys.defines, 'GLFW_KEY_{}'.format(key)),
                              w.screen.cursor_key_mode, extended,
                              _mods_to_glfw(mods), action).decode('ascii')))
        w.write_to_child(sequence)
Ejemplo n.º 3
0
def handle_result(args, result, target_window_id, boss):
    w = boss.window_id_map.get(target_window_id)
    tab = boss.active_tab
    if w is None:
        return

    if len(args) > 4:
        if not re.search(args[4], w.title):
            getattr(tab, args[1])(args[2])
            return
    else:
        if not re.search("n?vim", w.title):
            getattr(tab, args[1])(args[2])
            return

    mods, key, is_text = ku.parse_kittens_shortcut(args[3])
    if is_text:
        w.send_text(key)
        return

    extended = w.screen.extended_keyboard
    for action in actions(extended):
        sequence = (('\x1b_{}\x1b\\' if extended else '{}').format(
            keys.key_to_bytes(getattr(keys.defines, 'GLFW_KEY_{}'.format(key)),
                              w.screen.cursor_key_mode, extended, mods,
                              action).decode('ascii')))
        w.write_to_child(sequence)
Ejemplo n.º 4
0
def pass_key(key_combination: str, w):
    """
    pass key_combination to the kitty window w.
    Args:
        key_combination (str): keypress to pass. e.g. ctrl-j
        w (kitty window): window to pass the keys
    """
    mods, key, is_text = ku.parse_kittens_shortcut(key_combination)
    extended = w.screen.extended_keyboard
    for action in actions(extended):
        sequence = (('\x1b_{}\x1b\\' if extended else '{}').format(
            keys.key_to_bytes(
                getattr(keys.defines, 'GLFW_KEY_{}'.format(key.upper())),
                w.screen.cursor_key_mode, extended, convert_mods(mods),
                action).decode('ascii')))
        print(repr(sequence))
        w.write_to_child(sequence)
Ejemplo n.º 5
0
def handle_result(args, result, target_window_id, boss):
    w = boss.window_id_map.get(target_window_id)
    if w is None:
        return

    if w.screen.is_main_linebuf():
        getattr(w, args[1])()
        return

    mods, key, is_text = ku.parse_kittens_shortcut(args[2])
    if is_text:
        w.send_text(key)
        return

    extended = w.screen.extended_keyboard
    for action in actions(extended):
        sequence = (('\x1b_{}\x1b\\' if extended else '{}').format(
            keys.key_to_bytes(getattr(keys.defines, 'GLFW_KEY_{}'.format(key)),
                              w.screen.cursor_key_mode, extended, mods,
                              action).decode('ascii')))
        w.write_to_child(sequence)