From 14f5e10fd62b6cbb498127987f92e71a08d14cc1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 7 Dec 2020 16:15:44 +0530 Subject: [PATCH] Fix mapping of remote_control not working for actions that yield generators Fixes #3147 --- docs/changelog.rst | 2 ++ kitty/boss.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index fd3c16884..11d61a785 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -46,6 +46,8 @@ To update |kitty|, :doc:`follow the instructions `. interoperability. This means that doing a DECRC without a prior DECSC is now undefined (:iss:`1264`) +- Fix mapping ``remote_control send-text`` not working (:iss:`3147`) + 0.19.2 [2020-11-13] ------------------- diff --git a/kitty/boss.py b/kitty/boss.py index 6f9d3b1b3..d57ad4171 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -10,7 +10,8 @@ from contextlib import suppress from functools import partial from gettext import gettext as _ from typing import ( - Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union + Any, Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union, + cast ) from weakref import WeakValueDictionary @@ -363,9 +364,17 @@ class Boss: c = command_for_name(cmd) opts, items = parse_subcommand_cli(c, items) payload = c.message_to_kitty(global_opts, opts, items) - c.response_from_kitty(self, self.active_window, PayloadGetter(c, payload if isinstance(payload, dict) else {})) - except (Exception, SystemExit) as e: - self.show_error(_('remote_control mapping failed'), str(e)) + import types + if isinstance(cast(types.GeneratorType, payload), types.GeneratorType): + payloads = cast(types.GeneratorType, payload) + for x in payloads: + c.response_from_kitty(self, self.active_window, PayloadGetter(c, x if isinstance(x, dict) else {})) + else: + c.response_from_kitty(self, self.active_window, PayloadGetter(c, payload if isinstance(payload, dict) else {})) + except (Exception, SystemExit): + import traceback + tb = traceback.format_exc() + self.show_error(_('remote_control mapping failed'), tb) def peer_message_received(self, msg_bytes: bytes) -> Optional[bytes]: cmd_prefix = b'\x1bP@kitty-cmd'