-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreterm.py
39 lines (34 loc) · 1.07 KB
/
reterm.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
import importer
importer.reload_catherd_modules()
from log import logger
from nav import send_control_c
from kitty.fast_data_types import KeyEvent, GLFW_FKEY_ENTER, GLFW_FKEY_UP
from kittens.tui.handler import result_handler
l = logger('catherd.reterm')
def main(args):
pass
@result_handler(no_ui=True)
def handle_result(args, answer, target_window_id, boss):
try:
reterm(boss)
except:
l.exception("reterm blew chunks!")
keys = [KeyEvent(key=GLFW_FKEY_UP), KeyEvent(key=GLFW_FKEY_ENTER)]
_id_attr = '_catherd.reterm.window_id'
def reterm(boss):
win = boss.active_window
tab = boss.active_tab
window_id = getattr(tab, _id_attr, None)
for possible in tab.windows:
if possible.id == window_id:
win = possible
l.debug("Found previous win %s", win)
break
else:
l.debug("Trying active win %s", win)
if win is None:
return
setattr(tab, _id_attr, win.id)
send_control_c(win)
encoded_keys = b''.join(win.encoded_key(key) for key in keys)
win.write_to_child(encoded_keys)