From 402c8b680334986300da1beae47f2b1d3b05b652 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 25 Nov 2022 19:10:15 +0530 Subject: [PATCH] Use ANSI C escapes rather than python string literals --- kitty/options/definition.py | 4 ++-- kitty/options/utils.py | 4 ++-- kitty/rc/send_text.py | 5 +++-- kitty/window.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 249409114..8fe518e18 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3968,8 +3968,8 @@ when pressing specified shortcut keys. For example:: map ctrl+alt+a send_text all Special text This will send "Special text" when you press the :kbd:`Ctrl+Alt+A` key -combination. The text to be sent is a python string literal so you can use -escapes like :code:`\\\\x1b` to send control codes or :code:`\\\\u21fb` to send +combination. The text to be sent decodes :link:`ANSI C escapes ` +so you can use escapes like :code:`\\\\x1b` to send control codes or :code:`\\\\u21fb` to send Unicode characters (or you can just input the Unicode characters directly as UTF-8 text). You can use ``kitty +kitten show_key`` to get the key escape codes you want to emulate. diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 926aa63df..f078be96f 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -67,7 +67,7 @@ def shlex_parse(func: str, rest: str) -> FuncArgsType: def parse_send_text_bytes(text: str) -> bytes: - return python_string(text).encode('utf-8') + return defines.expand_ansi_c_escapes(text).encode('utf-8') @func_with_args('send_text') @@ -204,7 +204,7 @@ def paste_from_buffer(func: str, rest: str) -> FuncArgsType: def paste_parse(func: str, rest: str) -> FuncArgsType: text = '' try: - text = python_string(rest) + text = defines.expand_ansi_c_escapes(rest) except Exception: log_error('Ignoring invalid paste string: ' + rest) return func, [text] diff --git a/kitty/rc/send_text.py b/kitty/rc/send_text.py index 954fc8d8f..36cef6a9d 100644 --- a/kitty/rc/send_text.py +++ b/kitty/rc/send_text.py @@ -74,8 +74,9 @@ class SendText(RemoteCommand): short_desc = 'Send arbitrary text to specified windows' desc = ( 'Send arbitrary text to specified windows. The text follows Python' - ' escaping rules. So you can use escapes like :code:`\\\\x1b` to send control codes' - ' and :code:`\\\\u21fa` to send unicode characters. If you use the :option:`kitty @ send-text --match` option' + ' escaping rules. So you can use :link:`escapes `' + ' like :code:`\\\\x1b` to send control codes' + ' and :code:`\\\\u21fa` to send Unicode characters. If you use the :option:`kitty @ send-text --match` option' ' the text will be sent to all matched windows. By default, text is sent to' ' only the currently active window.' ) diff --git a/kitty/window.py b/kitty/window.py index 7206b3497..0be1c434e 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1547,7 +1547,7 @@ class Window: def show_last_non_empty_command_output(self) -> None: self.show_cmd_output(CommandOutput.last_non_empty, 'Last non-empty command output') - @ac('cp', 'Paste the specified text into the current window') + @ac('cp', 'Paste the specified text into the current window. ANSI C escapes are decoded.') def paste(self, text: str) -> None: self.paste_with_actions(text)