From c1af14c22a815f8ebcd0af433fed61683a4f4e1a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 Mar 2024 13:09:07 +0530 Subject: [PATCH] Fix @ send-key not working to send keys to self over TTY --- gen/go_code.py | 4 ++-- kitty/rc/base.py | 1 + kitty/rc/send_key.py | 14 ++++++++------ kitty/rc/send_text.py | 1 + tools/cmd/at/send_text.go | 1 - 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/gen/go_code.py b/gen/go_code.py index 7c9a70ce1..4267f2a7b 100755 --- a/gen/go_code.py +++ b/gen/go_code.py @@ -335,7 +335,6 @@ def go_declaration(self) -> str: def go_code_for_remote_command(name: str, cmd: RemoteCommand, template: str) -> str: template = '\n' + template[len('//go:build exclude'):] - NO_RESPONSE_BASE = 'false' af: List[str] = [] a = af.append af.extend(cmd.args.as_go_completion_code('ans')) @@ -405,13 +404,14 @@ def go_code_for_remote_command(name: str, cmd: RemoteCommand, template: str) -> argspec = cmd.args.spec if argspec: argspec = ' ' + argspec + NO_RESPONSE = 'true' if cmd.disallow_responses else 'false' ans = replace( template, CMD_NAME=name, __FILE__=__file__, CLI_NAME=name.replace('_', '-'), SHORT_DESC=serialize_as_go_string(cmd.short_desc), LONG_DESC=serialize_as_go_string(cmd.desc.strip()), IS_ASYNC='true' if cmd.is_asynchronous else 'false', - NO_RESPONSE_BASE=NO_RESPONSE_BASE, ADD_FLAGS_CODE='\n'.join(af), + NO_RESPONSE_BASE=NO_RESPONSE, ADD_FLAGS_CODE='\n'.join(af), WAIT_TIMEOUT=str(cmd.response_timeout), OPTIONS_DECLARATION_CODE='\n'.join(od), JSON_DECLARATION_CODE='\n'.join(jd), diff --git a/kitty/rc/base.py b/kitty/rc/base.py index b2199d671..e20a52b5d 100644 --- a/kitty/rc/base.py +++ b/kitty/rc/base.py @@ -331,6 +331,7 @@ class RemoteCommand: argspec = args_count = args_completion = ArgsHandling() field_to_option_map: Optional[Dict[str, str]] = None reads_streaming_data: bool = False + disallow_responses: bool = False def __init__(self) -> None: self.desc = self.desc or self.short_desc diff --git a/kitty/rc/send_key.py b/kitty/rc/send_key.py index 3bc6191a2..d71196f5a 100644 --- a/kitty/rc/send_key.py +++ b/kitty/rc/send_key.py @@ -21,6 +21,7 @@ class SendKey(RemoteCommand): + disallow_responses = True protocol_spec = __doc__ = ''' keys+/list.str: The keys to send match/str: A string indicating the window to send text to @@ -33,8 +34,12 @@ class SendKey(RemoteCommand): 'Send arbitrary key presses to specified windows. All specified keys are sent first as press events' ' then as release events in reverse order. Keys are sent to the programs running in the windows.' ' They are sent only if the current keyboard mode for the program supports the particular key.' - ' For example: send-key ctrl+a ctrl+b' - ) + ' For example: send-key ctrl+a ctrl+b. Note that errors are not reported, for technical reasons,' + ' so send-key always succeeds, even if no key was sent to any window.' + ) + # since send-key can send data over the tty to the window in which it was + # run --no-reponse is always in effect for it, hence errors are not + # reported. options_spec = MATCH_WINDOW_OPTION + '\n\n' + MATCH_TAB_OPTION.replace('--match -m', '--match-tab -t') + '''\n --all type=bool-set @@ -54,11 +59,8 @@ def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: Arg def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType: windows = self.windows_for_payload(boss, None, payload_get, window_match_name='match') keys = payload_get('keys') - sent = False for w in windows: - if not w.send_key(*keys): - sent = True - sent + w.send_key(*keys) return None diff --git a/kitty/rc/send_text.py b/kitty/rc/send_text.py index c38ba58d8..7a58faacc 100644 --- a/kitty/rc/send_text.py +++ b/kitty/rc/send_text.py @@ -72,6 +72,7 @@ def __call__(self, window: Window, focused: bool) -> None: class SendText(RemoteCommand): + disallow_responses = True protocol_spec = __doc__ = ''' data+/str: The data being sent. Can be either: text: followed by text or base64: followed by standard base64 encoded bytes match/str: A string indicating the window to send text to diff --git a/tools/cmd/at/send_text.go b/tools/cmd/at/send_text.go index ab0ab7911..7e6bad603 100644 --- a/tools/cmd/at/send_text.go +++ b/tools/cmd/at/send_text.go @@ -31,7 +31,6 @@ func make_file_gen(f *os.File) func(*rc_io_data) (bool, error) { } func parse_send_text(io_data *rc_io_data, args []string) error { - io_data.rc.NoResponse = true generators := make([]func(io_data *rc_io_data) (bool, error), 0, 1) if len(args) > 0 {