Skip to content

Commit 3d741d2

Browse files
author
Your Name
committed
#590: Bell ringing in default notification commands
1 parent ef557d6 commit 3d741d2

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

cecli/io.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,31 +1694,39 @@ def llm_started(self):
16941694
self.bell_on_next_input = True
16951695

16961696
def get_default_notification_command(self):
1697-
"""Return a default notification command based on the operating system."""
1697+
"""Return a command that triggers a system bell followed by a notification."""
16981698
import platform
1699+
import shutil
16991700

17001701
system = platform.system()
17011702

1702-
if system == "Darwin": # macOS
1703-
# Check for terminal-notifier first
1703+
# 1. Define the Bell component
1704+
if system == "Windows":
1705+
bell_cmd = "powershell -c [Console]::Beep(1000, 200)"
1706+
elif system == "Darwin":
1707+
bell_cmd = "osascript -e 'beep'"
1708+
else: # Linux/Unix
1709+
bell_cmd = "tput bel" if shutil.which("tput") else "echo -e '\\a'"
1710+
1711+
# 2. Define the Notification component
1712+
notif_cmd = None
1713+
if system == "Darwin":
17041714
if shutil.which("terminal-notifier"):
1705-
return f"terminal-notifier -title 'cecli' -message '{NOTIFICATION_MESSAGE}'"
1706-
# Fall back to osascript
1707-
return (
1708-
f'osascript -e \'display notification "{NOTIFICATION_MESSAGE}" with title "cecli"\''
1709-
)
1715+
notif_cmd = f"terminal-notifier -title 'cecli' -message '{NOTIFICATION_MESSAGE}'"
1716+
else:
1717+
notif_cmd = f'osascript -e \'display notification "{NOTIFICATION_MESSAGE}" with title "cecli"\''
1718+
17101719
elif system == "Linux":
1711-
# Check for common Linux notification tools
17121720
for cmd in ["notify-send", "zenity"]:
17131721
if shutil.which(cmd):
17141722
if cmd == "notify-send":
1715-
return f"notify-send 'cecli' '{NOTIFICATION_MESSAGE}'"
1723+
notif_cmd = f"notify-send 'cecli' '{NOTIFICATION_MESSAGE}'"
17161724
elif cmd == "zenity":
1717-
return f"zenity --notification --text='{NOTIFICATION_MESSAGE}'"
1718-
return None # No known notification tool found
1725+
notif_cmd = f"zenity --notification --text='{NOTIFICATION_MESSAGE}'"
1726+
break
1727+
17191728
elif system == "Windows":
1720-
# PowerShell toast notification
1721-
ps_command = (
1729+
ps_body = (
17221730
' "try {{ Add-Type -AssemblyName System.Runtime.WindowsRuntime; $null ='
17231731
" [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications,"
17241732
" ContentType = WindowsRuntime] }} catch {{}}; "
@@ -1734,9 +1742,15 @@ def get_default_notification_command(self):
17341742
"[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('cecli')"
17351743
'.Show($toast)"'
17361744
)
1737-
return "powershell -WindowStyle Hidden -Command" + ps_command
1745+
notif_cmd = f"powershell -WindowStyle Hidden -Command {ps_body}"
1746+
1747+
# 3. Concatenate them
1748+
if notif_cmd:
1749+
# Using ';' as a command separator works for both shell=True on Unix and Windows
1750+
return f"{bell_cmd} ; {notif_cmd}"
17381751

1739-
return None # Unknown system
1752+
# Fallback if no notification tool is found
1753+
return bell_cmd
17401754

17411755
def _send_notification(self):
17421756
# Cooldown to prevent notification spam

0 commit comments

Comments
 (0)