Skip to content

Commit

Permalink
Cleanup previous PR
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Nov 14, 2023
1 parent b5067c1 commit 0450697
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 40 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ The :doc:`ssh kitten <kittens/ssh>` is redesigned with powerful new features:
Detailed list of changes
-------------------------------------

0.32.0 [future]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- A new option :opt:`notify_on_cmd_finish` to show a desktop notification when a long running command finishes (:pull:`6817`)

0.31.0 [2023-11-08]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
22 changes: 8 additions & 14 deletions kitty/options/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3149,10 +3149,8 @@
'''
)

opt('notify_on_cmd_finish', 'never',
choices=('never', 'unfocused', 'invisible', 'always'),
long_text='''
Whether to send a desktop notification when a long-running command finishes
opt('notify_on_cmd_finish', 'never', option_type='notify_on_cmd_finish', long_text='''
Show a desktop notification when a long-running command finishes
(needs :opt:`shell_integration`).
The possible values are:
Expand All @@ -3168,17 +3166,13 @@
is not currently active.
:code:`always`
Always send a notification, even if the window is focused.
'''
)
Always send a notification, regardless of window state.
opt('notify_on_cmd_finish_min_duration', '5.0',
option_type="float",
long_text='''
Only send a notification if a command takes more than specified seconds of time.
It's not recommended to set a value too small, as you probably don't want a
notification when a command launches a new window and exit immediately (e.g. the
`code` command from vscode).
Furthermore, you can set the minimum duration for what is considered a
long running command. The default is 5 seconds. Specify a second argument
to set the duration. For example: :code:`invisible 15`.
Do not set the value too small, otherwise a command that launches a new OS Window
and exits will spam a notification.
'''
)

Expand Down
22 changes: 7 additions & 15 deletions kitty/options/parse.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions kitty/options/types.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions kitty/options/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,16 @@ def active_tab_title_template(x: str) -> Optional[str]:
return None if x == 'none' else x


def notify_on_cmd_finish(x: str) -> Tuple[str, float]:
parts = x.split()
if parts[0] not in ('never', 'unfocused', 'invisible', 'always'):
raise ValueError(f'Unknown notify_on_cmd_finish value: {x}')
duration = 5.0
if len(parts) > 1:
duration = float(parts[1])
return parts[0], duration


def config_or_absolute_path(x: str, env: Optional[Dict[str, str]] = None) -> Optional[str]:
if not x or x.lower() == 'none':
return None
Expand Down
12 changes: 5 additions & 7 deletions kitty/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def __init__(
self.current_mouse_event_button = 0
self.current_clipboard_read_ask: Optional[bool] = None
self.prev_osc99_cmd = NotificationCommand()
self.last_cmd_output_start_time = 0
self.last_cmd_output_start_time = 0.
self.actions_on_close: List[Callable[['Window'], None]] = []
self.actions_on_focus_change: List[Callable[['Window', bool], None]] = []
self.actions_on_removal: List[Callable[['Window'], None]] = []
Expand Down Expand Up @@ -1331,19 +1331,17 @@ def cmd_output_marking(self, is_start: int) -> None:

self.call_watchers(self.watchers.on_cmd_startstop, {"is_start": True, "time": start_time})
else:
if self.last_cmd_output_start_time > 0:
if self.last_cmd_output_start_time > 0.:
end_time = monotonic()
last_cmd_output_duration = end_time - self.last_cmd_output_start_time
self.last_cmd_output_start_time = 0
self.last_cmd_output_start_time = 0.

self.call_watchers(self.watchers.on_cmd_startstop, {"is_start": False, "time": end_time})

opts = get_options()
mode = opts.notify_on_cmd_finish
if mode == 'never':
return
mode, duration = opts.notify_on_cmd_finish

if last_cmd_output_duration >= opts.notify_on_cmd_finish_min_duration:
if last_cmd_output_duration >= duration and mode != 'never':
cmd = NotificationCommand()
cmd.title = 'kitty'
cmd.body = 'Command finished in a background window.\nClick to focus.'
Expand Down

0 comments on commit 0450697

Please sign in to comment.