🔧 chore(kitty): update scripts
This commit is contained in:
parent
fd3e37dc24
commit
d750ee71c5
2 changed files with 66 additions and 4 deletions
|
@ -1,9 +1,38 @@
|
||||||
|
from kitty.key_encoding import KeyEvent, parse_shortcut
|
||||||
|
from kittens.tui.handler import result_handler
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def encode_key_mapping(window, key_mapping):
|
||||||
|
mods, key = parse_shortcut(key_mapping)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
@result_handler(no_ui=True)
|
||||||
def handle_result(args, result, target_window_id, boss):
|
def handle_result(args, result, target_window_id, boss):
|
||||||
boss.active_tab.neighboring_window(args[1])
|
window = boss.window_id_map.get(target_window_id)
|
||||||
|
|
||||||
|
keymap = args[2]
|
||||||
|
|
||||||
handle_result.no_ui = True
|
cmd = window.child.foreground_cmdline[0]
|
||||||
|
if cmd == 'nvim':
|
||||||
|
encoded = encode_key_mapping(window, keymap)
|
||||||
|
window.write_to_child(encoded)
|
||||||
|
elif cmd == 'tmux':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
boss.active_tab.neighboring_window(args[1])
|
||||||
|
|
|
@ -1,15 +1,36 @@
|
||||||
# Based on MIT licensed code at https://github.com/chancez/dotfiles/blob/badc69d3895a6a942285amount26b8c372a55d77533eamount/kitty/.config/kitty/relative_resize.py
|
# Based on MIT licensed code at https://github.com/chancez/dotfiles/blob/badc69d3895a6a942285amount26b8c372a55d77533eamount/kitty/.config/kitty/relative_resize.py
|
||||||
from kittens.tui.handler import result_handler
|
from kittens.tui.handler import result_handler
|
||||||
|
from kitty.key_encoding import KeyEvent, parse_shortcut
|
||||||
|
|
||||||
|
|
||||||
|
def encode_key_mapping(window, key_mapping):
|
||||||
|
mods, key = parse_shortcut(key_mapping)
|
||||||
|
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 main(args):
|
def main(args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def relative_resize_window(direction, amount, target_window_id, boss):
|
def relative_resize_window(direction, amount, target_window_id, boss):
|
||||||
window = boss.window_id_map.get(target_window_id)
|
window = boss.window_id_map.get(target_window_id)
|
||||||
if window is None:
|
if window is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
neighbors = boss.active_tab.current_layout.neighbors_for_window(window, boss.active_tab.windows)
|
neighbors = boss.active_tab.current_layout.neighbors_for_window(
|
||||||
|
window, boss.active_tab.windows
|
||||||
|
)
|
||||||
current_window_id = boss.active_tab.active_window
|
current_window_id = boss.active_tab.active_window
|
||||||
|
|
||||||
left_neighbors = neighbors.get('left')
|
left_neighbors = neighbors.get('left')
|
||||||
|
@ -57,8 +78,20 @@ def relative_resize_window(direction, amount, target_window_id, boss):
|
||||||
elif direction == 'down' and bottom_neighbors:
|
elif direction == 'down' and bottom_neighbors:
|
||||||
boss.active_tab.resize_window('taller', amount)
|
boss.active_tab.resize_window('taller', amount)
|
||||||
|
|
||||||
|
|
||||||
@result_handler(no_ui=True)
|
@result_handler(no_ui=True)
|
||||||
def handle_result(args, result, target_window_id, boss):
|
def handle_result(args, result, target_window_id, boss):
|
||||||
direction = args[1]
|
direction = args[1]
|
||||||
amount = int(args[2])
|
amount = int(args[2])
|
||||||
relative_resize_window(direction, amount, target_window_id, boss)
|
window = boss.window_id_map.get(target_window_id)
|
||||||
|
|
||||||
|
keymap = args[3]
|
||||||
|
|
||||||
|
cmd = window.child.foreground_cmdline[0]
|
||||||
|
if cmd == 'nvim':
|
||||||
|
encoded = encode_key_mapping(window, keymap)
|
||||||
|
window.write_to_child(encoded)
|
||||||
|
elif cmd == 'tmux':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
relative_resize_window(direction, amount, target_window_id, boss)
|
||||||
|
|
Loading…
Add table
Reference in a new issue