More work on remote control

This commit is contained in:
Kovid Goyal 2018-01-07 17:08:29 +05:30
parent 9e361700d2
commit c64fd1760c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 30 additions and 3 deletions

View File

@ -16,6 +16,7 @@ from .fast_data_types import (
)
from .fonts.render import prerender, resize_fonts, set_font_family
from .keys import get_shortcut
from .remote_control import handle_cmd
from .session import create_session
from .tabs import SpecialWindow, TabManager
from .utils import (
@ -128,7 +129,11 @@ class Boss:
def handle_remote_cmd(self, cmd, window=None):
response = None
if self.opts.allow_remote_control:
pass
try:
response = handle_cmd(self, window, cmd)
except Exception as err:
import traceback
response = {'ok': False, 'error': str(err), 'tb': traceback.format_exc()}
else:
response = {'ok': False, 'error': 'Remote control is disabled. Add allow_remote_control yes to your kitty.conf'}
if response is not None:

View File

@ -757,7 +757,7 @@ dispatch_dcs(Screen *screen, PyObject DUMP_UNUSED *dump_callback) {
break;
case '@':
if (startswith(screen->parser_buf + 1, screen->parser_buf_pos - 2, "kitty-cmd{")) {
PyObject *cmd = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, screen->parser_buf + 11, screen->parser_buf_pos - 11);
PyObject *cmd = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, screen->parser_buf + 10, screen->parser_buf_pos - 10);
if (cmd != NULL) {
REPORT_OSC2(screen_handle_cmd, (char)screen->parser_buf[0], cmd);
screen_handle_cmd(screen, cmd);

View File

@ -28,11 +28,31 @@ def parse_subcommand_cli(func, args):
return opts, items
@cmd('List all windows')
@cmd(
'List all tabs/windows'
)
def cmd_ls(global_opts, opts, args):
pass
def ls(boss, window):
raise NotImplementedError()
def handle_cmd(boss, window, cmd):
cmd = json.loads(cmd)
v = cmd['version']
if tuple(v)[:2] > version[:2]:
return {'ok': False, 'error': 'The kitty client you are using to send remote commands is newer than this kitty instance. This is not supported.'}
func = partial(globals()[cmd['cmd']], boss, window)
payload = cmd.get('payload')
ans = func(payload) if payload is not None else func()
response = {'ok': True}
if ans is not None:
response['data'] = ans
return response
global_options_spec = partial('''\
'''.format, appname=appname)
@ -97,3 +117,5 @@ def main(args):
if response.get('tb'):
print(response['tb'], file=sys.stderr)
raise SystemExit(response['error'])
if 'data' in response:
print(response['data'])