-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgrab.py
33 lines (27 loc) · 1.07 KB
/
grab.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
import os
from typing import Any, Dict, List, Sequence
from kittens.tui.handler import result_handler
from kitty.typing import BossType
import _grab_ui
def main(args: List[str]) -> None:
pass
@result_handler(no_ui=True)
def handle_result(args: List[str], data: Dict[str, Any], target_window_id: int, boss: BossType) -> None:
window = boss.window_id_map.get(target_window_id)
if window is None:
return
tab = window.tabref()
if tab is None:
return
content = window.as_text(as_ansi=True, add_history=True,
add_wrap_markers=True)
content = content.replace('\r\n', '\n').replace('\r', '\n')
n_lines = content.count('\n')
top_line = (n_lines - (window.screen.lines - 1) - window.screen.scrolled_by)
boss._run_kitten(_grab_ui.__file__, args=[
'--title={}'.format(window.title),
'--cursor-x={}'.format(window.screen.cursor.x),
'--cursor-y={}'.format(window.screen.cursor.y),
'--top-line={}'.format(top_line)],
input_data=content.encode('utf-8'),
window=window)