From eeaf67079a4eb954ce0bf80d8733f9cf66f9e2f5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 11 May 2021 10:33:01 +0530 Subject: [PATCH] DRYer --- kitty/boss.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index ca0ae2cc9..4def050a2 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -742,11 +742,15 @@ class Boss: window_for_dispatch: Optional[Window] = None, dispatch_type: str = 'KeyPress' ) -> bool: + + def report_match(f: Callable) -> None: + if self.args.debug_keyboard: + print(f'\x1b[35m{dispatch_type}\x1b[m matched action:', func_name(f), flush=True) + if key_action is not None: f = getattr(self, key_action.func, None) if f is not None: - if self.args.debug_keyboard: - print(f'{dispatch_type} matched action:', func_name(f), flush=True) + report_match(f) passthrough = f(*key_action.args) if passthrough is not True: return True @@ -762,8 +766,7 @@ class Boss: f = getattr(tab, key_action.func, getattr(window, key_action.func, None)) if f is not None: passthrough = f(*key_action.args) - if self.args.debug_keyboard: - print(f'{dispatch_type} matched action:', func_name(f)) + report_match(f) if passthrough is not True: return True return False