mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 07:17:54 +08:00
core/cli: keep a prompt notification on screen
A prompt notification went out with the library defaults: the notification server's own expiry. A desktop server drops such a notification after a few seconds, so the announcement of a blocked turn had usually slid into the notification tray by the time the human looked back. It now goes out without expiry (`timeout=0`, the freedesktop value for "until dismissed"). Urgency is left alone: measured on KDE Plasma, `critical` keeps the notification up just the same, but paints it as urgent and asks the platform's Focus mode to let it through — decoration a prompt does not need. Dismissing is already the prompt's own job once it is answered, so nothing lingers.
This commit is contained in:
@@ -60,6 +60,14 @@ _BUTTONS: tuple[tuple[str, str], ...] = (
|
||||
_MAX_TITLE = 80
|
||||
_MAX_MESSAGE = 200
|
||||
|
||||
#: Seconds a desktop notification may stay up; ``0`` is the freedesktop value
|
||||
#: for "until dismissed" (``-1`` would hand the notification server's default
|
||||
#: back, which is a few seconds — after that the notification collapses into
|
||||
#: the tray, where nobody waiting on a prompt looks). Urgency stays at the
|
||||
#: library default: ``critical`` keeps the notification up just the same, but
|
||||
#: paints it as urgent and asks the platform's Focus mode to let it through.
|
||||
_NO_EXPIRY = 0
|
||||
|
||||
|
||||
def _clean(text: str, limit: int) -> str:
|
||||
"""One line, no control characters, truncated to *limit* characters."""
|
||||
@@ -171,6 +179,11 @@ class DesktopNotifierChannel:
|
||||
send(
|
||||
title=request.title,
|
||||
message=request.message,
|
||||
# A prompt holds the turn until it is answered, so the
|
||||
# notification must still be on screen when the human looks
|
||||
# back. Dismissing is the prompt's own job once it is
|
||||
# answered, so nothing lingers.
|
||||
timeout=_NO_EXPIRY,
|
||||
buttons=buttons,
|
||||
reply_field=reply,
|
||||
)
|
||||
|
||||
@@ -22,6 +22,11 @@ class Capability(Enum):
|
||||
THREAD = ...
|
||||
TIMEOUT = ...
|
||||
|
||||
class Urgency(Enum):
|
||||
Critical = ...
|
||||
Normal = ...
|
||||
Low = ...
|
||||
|
||||
class Button:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -50,7 +55,7 @@ class DesktopNotifier:
|
||||
self,
|
||||
title: str,
|
||||
message: str,
|
||||
urgency: Any = ...,
|
||||
urgency: Urgency = ...,
|
||||
icon: Any = ...,
|
||||
buttons: Sequence[Button] = ...,
|
||||
reply_field: ReplyField | None = None,
|
||||
|
||||
Reference in New Issue
Block a user