From 6ad9f6fd4053b4d7959d0d63bbe8083f4a4d6370 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Nov 2024 09:34:10 +0530 Subject: [PATCH] ... --- docs/launch.rst | 21 +++++++++++---------- kitty/launch.py | 6 +++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/launch.rst b/docs/launch.rst index fb11cdf89..952754187 100644 --- a/docs/launch.rst +++ b/docs/launch.rst @@ -122,47 +122,48 @@ create :file:`~/.config/kitty/mywatcher.py` and use :option:`launch --watcher` = .. code-block:: python # ~/.config/kitty/mywatcher.py - from typing import Any, Dict + from typing import Any from kitty.boss import Boss from kitty.window import Window - def on_load(boss: Boss) -> None: + def on_load(boss: Boss, data: dict[str, Any]) -> None: # This is a special function that is called just once when this watcher # module is first loaded, can be used to perform any initializztion/one - # time setup. + # time setup. Any exceptions in this function are printed to kitty's + # STDERR but otherwise ignored. ... - def on_resize(boss: Boss, window: Window, data: Dict[str, Any]) -> None: + def on_resize(boss: Boss, window: Window, data: dict[str, Any]) -> None: # Here data will contain old_geometry and new_geometry # Note that resize is also called the first time a window is created # which can be detected as old_geometry will have all zero values, in # particular, old_geometry.xnum and old_geometry.ynum will be zero. ... - def on_focus_change(boss: Boss, window: Window, data: Dict[str, Any])-> None: + def on_focus_change(boss: Boss, window: Window, data: dict[str, Any])-> None: # Here data will contain focused ... - def on_close(boss: Boss, window: Window, data: Dict[str, Any])-> None: + def on_close(boss: Boss, window: Window, data: dict[str, Any])-> None: # called when window is closed, typically when the program running in # it exits ... - def on_set_user_var(boss: Boss, window: Window, data: Dict[str, Any]) -> None: + def on_set_user_var(boss: Boss, window: Window, data: dict[str, Any]) -> None: # called when a "user variable" is set or deleted on a window. Here # data will contain key and value ... - def on_title_change(boss: Boss, window: Window, data: Dict[str, Any]) -> None: + def on_title_change(boss: Boss, window: Window, data: dict[str, Any]) -> None: # called when the window title is changed on a window. Here # data will contain title and from_child. from_child will be True # when a title change was requested via escape code from the program # running in the terminal ... - def on_cmd_startstop(boss: Boss, window: Window, data: Dict[str, Any]) -> None: + def on_cmd_startstop(boss: Boss, window: Window, data: dict[str, Any]) -> None: # called when the shell starts/stops executing a command. Here # data will contain is_start, cmdline and time. ... @@ -177,7 +178,7 @@ would pass to ``kitten @``. For example: .. code-block:: python - def on_resize(boss: Boss, window: Window, data: Dict[str, Any]) -> None: + def on_resize(boss: Boss, window: Window, data: dict[str, Any]) -> None: # send some text to the resized window boss.call_remote_control(window, ('send-text', f'--match=id:{window.id}', 'hello world')) diff --git a/kitty/launch.py b/kitty/launch.py index a9a59604c..2f8e728bf 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -439,7 +439,11 @@ def load_watch_modules(watchers: Iterable[str]) -> Optional[Watchers]: watcher_modules[path] = m w = m.get('on_load') if callable(w): - w(boss) + try: + w(boss, {}) + except Exception: + import traceback + traceback.print_exc() if m is False: continue w = m.get('on_close')