mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Support combined notify and bell on command finish
This commit is contained in:
@@ -3482,6 +3482,10 @@ Second, the action to perform. The default is :code:`notify`. The possible value
|
|||||||
:code:`bell`
|
:code:`bell`
|
||||||
Ring the terminal bell.
|
Ring the terminal bell.
|
||||||
|
|
||||||
|
:code:`notify-bell`
|
||||||
|
Send a desktop notification and ring the terminal bell.
|
||||||
|
The arguments are the same as for `notify`.
|
||||||
|
|
||||||
:code:`command`
|
:code:`command`
|
||||||
Run a custom command. All subsequent arguments are the cmdline to run.
|
Run a custom command. All subsequent arguments are the cmdline to run.
|
||||||
|
|
||||||
|
|||||||
@@ -803,10 +803,10 @@ def notify_on_cmd_finish(x: str) -> NotifyOnCmdFinish:
|
|||||||
cmdline: tuple[str, ...] = ()
|
cmdline: tuple[str, ...] = ()
|
||||||
clear_on = default_clear_on
|
clear_on = default_clear_on
|
||||||
if len(parts) > 2:
|
if len(parts) > 2:
|
||||||
if parts[2] not in ('notify', 'bell', 'command'):
|
if parts[2] not in ('notify', 'bell', 'notify-bell', 'command'):
|
||||||
raise ValueError(f'Unknown notify_on_cmd_finish action: {parts[2]}')
|
raise ValueError(f'Unknown notify_on_cmd_finish action: {parts[2]}')
|
||||||
action = parts[2]
|
action = parts[2]
|
||||||
if action == 'notify':
|
if action.startswith('notify'):
|
||||||
if len(parts) > 3:
|
if len(parts) > 3:
|
||||||
con: list[ClearOn] = []
|
con: list[ClearOn] = []
|
||||||
for x in parts[3].split():
|
for x in parts[3].split():
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ from .fast_data_types import (
|
|||||||
wakeup_main_loop,
|
wakeup_main_loop,
|
||||||
)
|
)
|
||||||
from .keys import keyboard_mode_name, mod_mask
|
from .keys import keyboard_mode_name, mod_mask
|
||||||
|
from .notifications import NotificationManager
|
||||||
from .options.types import Options
|
from .options.types import Options
|
||||||
from .progress import Progress
|
from .progress import Progress
|
||||||
from .rgb import to_color
|
from .rgb import to_color
|
||||||
@@ -1611,16 +1612,23 @@ class Window:
|
|||||||
cmd.only_when = OnlyWhen(when)
|
cmd.only_when = OnlyWhen(when)
|
||||||
if not nm.is_notification_allowed(cmd, self.id):
|
if not nm.is_notification_allowed(cmd, self.id):
|
||||||
return
|
return
|
||||||
if action == 'notify':
|
|
||||||
if self.last_cmd_end_notification is not None:
|
def notify(window: Window, opts: Options, nm: NotificationManager) -> None:
|
||||||
|
if window.last_cmd_end_notification is not None:
|
||||||
if 'next' in opts.notify_on_cmd_finish.clear_on:
|
if 'next' in opts.notify_on_cmd_finish.clear_on:
|
||||||
nm.close_notification(self.last_cmd_end_notification[0])
|
nm.close_notification(window.last_cmd_end_notification[0])
|
||||||
self.last_cmd_end_notification = None
|
window.last_cmd_end_notification = None
|
||||||
notification_id = nm.notify_with_command(cmd, self.id)
|
notification_id = nm.notify_with_command(cmd, window.id)
|
||||||
if notification_id is not None:
|
if notification_id is not None:
|
||||||
self.last_cmd_end_notification = notification_id, cmd.only_when
|
window.last_cmd_end_notification = notification_id, cmd.only_when
|
||||||
|
|
||||||
|
if action == 'notify':
|
||||||
|
notify(self, opts, nm)
|
||||||
elif action == 'bell':
|
elif action == 'bell':
|
||||||
self.screen.bell()
|
self.screen.bell()
|
||||||
|
elif action == 'notify-bell':
|
||||||
|
notify(self, opts, nm)
|
||||||
|
self.screen.bell()
|
||||||
elif action == 'command':
|
elif action == 'command':
|
||||||
open_cmd([x.replace('%c', self.last_cmd_cmdline).replace('%s', exit_status) for x in notify_cmdline])
|
open_cmd([x.replace('%c', self.last_cmd_cmdline).replace('%s', exit_status) for x in notify_cmdline])
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user