Allow mapping arbitrary remote control commands to key presses in kitty.conf
This commit is contained in:
@@ -339,6 +339,21 @@ class Boss:
|
||||
response = {'ok': False, 'error': 'Remote control is disabled. Add allow_remote_control to your kitty.conf'}
|
||||
return response
|
||||
|
||||
def remote_control(self, *args: str) -> None:
|
||||
from .remote_control import parse_rc_args
|
||||
from .rc.base import command_for_name, parse_subcommand_cli, PayloadGetter
|
||||
try:
|
||||
global_opts, items = parse_rc_args(['@'] + list(args))
|
||||
if not items:
|
||||
return
|
||||
cmd = items[0]
|
||||
c = command_for_name(cmd)
|
||||
opts, items = parse_subcommand_cli(c, items)
|
||||
payload = c.message_to_kitty(global_opts, opts, items)
|
||||
c.response_from_kitty(self, self.active_window, PayloadGetter(c, payload if isinstance(payload, dict) else {}))
|
||||
except (Exception, SystemExit) as e:
|
||||
self.show_error(_('remote_control mapping failed'), str(e))
|
||||
|
||||
def peer_message_received(self, msg_bytes: bytes) -> Optional[bytes]:
|
||||
msg = msg_bytes.decode('utf-8')
|
||||
cmd_prefix = '\x1bP@kitty-cmd'
|
||||
|
||||
@@ -240,6 +240,15 @@ def set_colors(func: str, rest: str) -> FuncArgsType:
|
||||
return func, r
|
||||
|
||||
|
||||
@func_with_args('remote_control')
|
||||
def remote_control(func: str, rest: str) -> FuncArgsType:
|
||||
import shlex
|
||||
r = shlex.split(rest)
|
||||
if len(r) < 1:
|
||||
log_error('Too few arguments to remote_control function')
|
||||
return func, r
|
||||
|
||||
|
||||
@func_with_args('nth_window')
|
||||
def nth_window(func: str, rest: str) -> FuncArgsType:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user