...
This commit is contained in:
parent
c3c63d3a1e
commit
6ad9f6fd40
2 changed files with 16 additions and 11 deletions
|
|
@ -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'))
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue