mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 01:08:10 +02:00
Fix @ send-key not working to send keys to self over TTY
This commit is contained in:
@@ -335,7 +335,6 @@ class JSONField:
|
|||||||
|
|
||||||
def go_code_for_remote_command(name: str, cmd: RemoteCommand, template: str) -> str:
|
def go_code_for_remote_command(name: str, cmd: RemoteCommand, template: str) -> str:
|
||||||
template = '\n' + template[len('//go:build exclude'):]
|
template = '\n' + template[len('//go:build exclude'):]
|
||||||
NO_RESPONSE_BASE = 'false'
|
|
||||||
af: List[str] = []
|
af: List[str] = []
|
||||||
a = af.append
|
a = af.append
|
||||||
af.extend(cmd.args.as_go_completion_code('ans'))
|
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
|
argspec = cmd.args.spec
|
||||||
if argspec:
|
if argspec:
|
||||||
argspec = ' ' + argspec
|
argspec = ' ' + argspec
|
||||||
|
NO_RESPONSE = 'true' if cmd.disallow_responses else 'false'
|
||||||
ans = replace(
|
ans = replace(
|
||||||
template,
|
template,
|
||||||
CMD_NAME=name, __FILE__=__file__, CLI_NAME=name.replace('_', '-'),
|
CMD_NAME=name, __FILE__=__file__, CLI_NAME=name.replace('_', '-'),
|
||||||
SHORT_DESC=serialize_as_go_string(cmd.short_desc),
|
SHORT_DESC=serialize_as_go_string(cmd.short_desc),
|
||||||
LONG_DESC=serialize_as_go_string(cmd.desc.strip()),
|
LONG_DESC=serialize_as_go_string(cmd.desc.strip()),
|
||||||
IS_ASYNC='true' if cmd.is_asynchronous else 'false',
|
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),
|
WAIT_TIMEOUT=str(cmd.response_timeout),
|
||||||
OPTIONS_DECLARATION_CODE='\n'.join(od),
|
OPTIONS_DECLARATION_CODE='\n'.join(od),
|
||||||
JSON_DECLARATION_CODE='\n'.join(jd),
|
JSON_DECLARATION_CODE='\n'.join(jd),
|
||||||
|
|||||||
@@ -331,6 +331,7 @@ class RemoteCommand:
|
|||||||
argspec = args_count = args_completion = ArgsHandling()
|
argspec = args_count = args_completion = ArgsHandling()
|
||||||
field_to_option_map: Optional[Dict[str, str]] = None
|
field_to_option_map: Optional[Dict[str, str]] = None
|
||||||
reads_streaming_data: bool = False
|
reads_streaming_data: bool = False
|
||||||
|
disallow_responses: bool = False
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.desc = self.desc or self.short_desc
|
self.desc = self.desc or self.short_desc
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
class SendKey(RemoteCommand):
|
class SendKey(RemoteCommand):
|
||||||
|
disallow_responses = True
|
||||||
protocol_spec = __doc__ = '''
|
protocol_spec = __doc__ = '''
|
||||||
keys+/list.str: The keys to send
|
keys+/list.str: The keys to send
|
||||||
match/str: A string indicating the window to send text to
|
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'
|
'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.'
|
' 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.'
|
' 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
|
options_spec = MATCH_WINDOW_OPTION + '\n\n' + MATCH_TAB_OPTION.replace('--match -m', '--match-tab -t') + '''\n
|
||||||
--all
|
--all
|
||||||
type=bool-set
|
type=bool-set
|
||||||
@@ -54,11 +59,8 @@ Do not send text to the active window, even if it is one of the matched windows.
|
|||||||
def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
|
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')
|
windows = self.windows_for_payload(boss, None, payload_get, window_match_name='match')
|
||||||
keys = payload_get('keys')
|
keys = payload_get('keys')
|
||||||
sent = False
|
|
||||||
for w in windows:
|
for w in windows:
|
||||||
if not w.send_key(*keys):
|
w.send_key(*keys)
|
||||||
sent = True
|
|
||||||
sent
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class FocusChangedSession(SessionAction):
|
|||||||
|
|
||||||
|
|
||||||
class SendText(RemoteCommand):
|
class SendText(RemoteCommand):
|
||||||
|
disallow_responses = True
|
||||||
protocol_spec = __doc__ = '''
|
protocol_spec = __doc__ = '''
|
||||||
data+/str: The data being sent. Can be either: text: followed by text or base64: followed by standard base64 encoded bytes
|
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
|
match/str: A string indicating the window to send text to
|
||||||
|
|||||||
@@ -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 {
|
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)
|
generators := make([]func(io_data *rc_io_data) (bool, error), 0, 1)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user