-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpounce.py
61 lines (50 loc) · 1.68 KB
/
pounce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from kittens.tui.handler import result_handler
from kitty.key_encoding import KeyEvent, parse_shortcut
from kitty.boss import Boss
from kitty.window import Window
from typing import List
def is_nvim(window: Window) -> bool:
user_vars = window.user_vars
if user_vars.get("KITTY_IN_NVIM") is not None:
return True
else:
return False
def encode_keyevent(window: Window, shortcut: str) -> bytes:
mods, key = parse_shortcut(shortcut)
event = KeyEvent(
mods=mods,
key=key,
shift=bool(mods & 1),
alt=bool(mods & 2),
ctrl=bool(mods & 4),
super=bool(mods & 8),
hyper=bool(mods & 16),
meta=bool(mods & 32),
).as_window_system_event()
return window.encoded_key(event)
def send_keyevent(window: Window, shortcut: str) -> None:
for keymap in shortcut.split(">"):
keyevent = encode_keyevent(window, keymap)
window.write_to_child(keyevent)
def main(args: List[str]) -> str:
pass
@result_handler(no_ui=True)
def handle_result(
args: List[str], answer: str, target_window_id: int, boss: Boss
) -> None:
target = boss.window_id_map.get(target_window_id)
if target is None:
return
if is_nvim(target) and len(args) == 3:
shortcut = args[1]
send_keyevent(target, shortcut)
else:
direction = args[2]
neighbor_window_id = boss.active_tab.neighboring_group_id(direction)
if neighbor_window_id is None:
return
boss.active_tab.windows.set_active_group(neighbor_window_id)
current = boss.active_window
if is_nvim(current):
shortcut = args[1]
send_keyevent(current, shortcut)