mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 11:11:47 +02:00
more work on porting command parsing to Go
This commit is contained in:
@@ -193,12 +193,13 @@ class ArgsHandling:
|
||||
yield f'args = append(args, "{x}")'
|
||||
yield '}'
|
||||
if self.minimum_count > -1:
|
||||
yield f'if len(args) < {self.minimum_count} {{ return fmt.Errorf("%s", Must specify at least {self.minimum_count} arguments to {cmd_name}) }}'
|
||||
yield f'if len(args) < {self.minimum_count} {{ return fmt.Errorf("%s", "Must specify at least {self.minimum_count} arguments to {cmd_name}") }}'
|
||||
if self.args_choices:
|
||||
achoices = tuple(self.args_choices())
|
||||
yield 'achoices := map[string]bool{' + ' '.join(f'"{x}":true,' for x in achoices) + '}'
|
||||
yield 'for _, a := range args {'
|
||||
yield 'if !achoices[a] { return fmt.Errorf("Not a valid choice: %s. Allowed values are: %s", a, "' + ', '.join(achoices) + '") }'
|
||||
yield '}'
|
||||
if self.json_field:
|
||||
jf = self.json_field
|
||||
dest = f'payload.{jf.capitalize()}'
|
||||
@@ -240,6 +241,7 @@ class ArgsHandling:
|
||||
return
|
||||
if jt == 'dict.str':
|
||||
yield f'{dest} = parse_key_val_args(args)'
|
||||
return
|
||||
raise TypeError(f'Unknown args handling for cmd: {cmd_name}')
|
||||
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ default=false
|
||||
Don't wait for a response from kitty. This means that even if setting the background image
|
||||
failed, the command will exit with a success code.
|
||||
''' + '\n\n' + MATCH_WINDOW_OPTION
|
||||
args = RemoteCommand.Args(spec='PATH_TO_PNG_IMAGE', count=1, special_parse='!read_window_logo(args[0])', completion={
|
||||
args = RemoteCommand.Args(spec='PATH_TO_PNG_IMAGE', count=1, json_field='data', special_parse='!read_window_logo(args[0])', completion={
|
||||
'files': ('PNG Images', ('*.png',))})
|
||||
images_in_flight: Dict[str, IO[bytes]] = {}
|
||||
is_asynchronous = True
|
||||
|
||||
@@ -37,7 +37,7 @@ By default, background opacity are only changed for the currently active window.
|
||||
cause background opacity to be changed in all windows.
|
||||
|
||||
''' + '\n\n' + MATCH_WINDOW_OPTION + '\n\n' + MATCH_TAB_OPTION.replace('--match -m', '--match-tab -t')
|
||||
args = RemoteCommand.Args(spec='OPACITY', count=1, json_field='opacity')
|
||||
args = RemoteCommand.Args(spec='OPACITY', count=1, json_field='opacity', special_parse='parse_opacity(args[0])')
|
||||
|
||||
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
|
||||
opacity = max(0.1, min(float(args[0]), 1.0))
|
||||
|
||||
Reference in New Issue
Block a user