More work on porting rc commands

This commit is contained in:
Kovid Goyal 2022-08-30 21:05:31 +05:30
parent a4b2e2a196
commit 192eccc6cc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 25 additions and 4 deletions

View File

@ -126,14 +126,27 @@ def build_go_code(name: str, cmd: RemoteCommand, seq: OptionSpecSeq, template: s
handled_fields: Set[str] = set() handled_fields: Set[str] = set()
jc.extend(cmd.args.as_go_code(name, field_types, handled_fields)) jc.extend(cmd.args.as_go_code(name, field_types, handled_fields))
unhandled = {}
used_options = set()
for field in json_fields: for field in json_fields:
if field.field in option_map: oq = (cmd.field_to_option_map or {}).get(field.field, field.field)
o = option_map[field.field] if oq in option_map:
o = option_map[oq]
used_options.add(oq)
jc.append(f'payload.{field.struct_field_name} = options_{name}.{o.go_var_name}') jc.append(f'payload.{field.struct_field_name} = options_{name}.{o.go_var_name}')
elif field.field in handled_fields: elif field.field in handled_fields:
pass pass
else: else:
print(f'Cant map field: {field.field} for cmd: {name}', file=sys.stderr) unhandled[field.field] = field
for x in tuple(unhandled):
if x == 'match_window' and 'match' in option_map and 'match' not in used_options:
used_options.add('match')
o = option_map['match']
field = unhandled[x]
jc.append(f'payload.{field.struct_field_name} = options_{name}.{o.go_var_name}')
del unhandled[x]
if unhandled:
raise SystemExit(f'Cant map fields: {", ".join(unhandled)} for cmd: {name}')
argspec = cmd.args.spec argspec = cmd.args.spec
if argspec: if argspec:
@ -228,7 +241,7 @@ def update_at_commands() -> None:
os.remove(dest) os.remove(dest)
with open(dest, 'w') as f: with open(dest, 'w') as f:
f.write(code) f.write(code)
print('TODO: test set_window_logo, set_window_background, set_font_size, send_text, env, scroll_window', file=sys.stderr) print('\x1b[31mTODO\x1b[m: test set_window_logo, set_window_background, set_font_size, send_text, env, scroll_window', file=sys.stderr)
def main() -> None: def main() -> None:

View File

@ -261,6 +261,7 @@ class RemoteCommand:
options_class: Type[RCOptions] = RCOptions options_class: Type[RCOptions] = RCOptions
protocol_spec: str = '' protocol_spec: str = ''
argspec = args_count = args_completion = ArgsHandling() argspec = args_count = args_completion = ArgsHandling()
field_to_option_map: Optional[Dict[str, str]] = None
def __init__(self) -> None: def __init__(self) -> None:
self.desc = self.desc or self.short_desc self.desc = self.desc or self.short_desc

View File

@ -69,6 +69,8 @@ type=bool-set
Get text from the window this command is run in, rather than the active window. Get text from the window this command is run in, rather than the active window.
''' '''
field_to_option_map = {'wrap_markers': 'add_wrap_markers', 'cursor': 'add_cursor'}
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType: def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
return { return {
'match': opts.match, 'match': opts.match,

View File

@ -47,6 +47,11 @@ class Launch(RemoteCommand):
logo_position/str: Window logo position as string or empty string to use default logo_position/str: Window logo position as string or empty string to use default
logo_alpha/float: Window logo alpha or -1 to use default logo_alpha/float: Window logo alpha or -1 to use default
self/bool: Boolean, if True use tab the command was run in self/bool: Boolean, if True use tab the command was run in
os_window_title/str: Title for OS Window
os_window_name/str: WM_NAME for OS Window
os_window_class/str: WM_CLASS for OS Window
color/list.str: list of color specifications such as foreground=red
watcher/list.str: list of paths to watcher files
''' '''
short_desc = 'Run an arbitrary process in a new window/tab' short_desc = 'Run an arbitrary process in a new window/tab'