mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Start work on implementing closing of notifications
This commit is contained in:
@@ -179,7 +179,7 @@ Key Value Default Description
|
|||||||
|
|
||||||
``p`` One of ``title``, ``title`` Whether the payload is the notification title or body or query. If a
|
``p`` One of ``title``, ``title`` Whether the payload is the notification title or body or query. If a
|
||||||
``body``, ``close`` notification has no title, the body will be used as title. Terminal
|
``body``, ``close`` notification has no title, the body will be used as title. Terminal
|
||||||
, ``?`` emulators should ignore payloads of unknown type to allow for future
|
, ``?`` emulators should ignore payloads of unknown type to allow for future
|
||||||
expansion of this protocol.
|
expansion of this protocol.
|
||||||
|
|
||||||
``o`` One of ``always``, ``always`` When to honor the notification request. ``unfocused`` means when the window
|
``o`` One of ``always``, ``always`` When to honor the notification request. ``unfocused`` means when the window
|
||||||
|
|||||||
@@ -78,6 +78,14 @@ class NotifyImplementation:
|
|||||||
notify_implementation = NotifyImplementation()
|
notify_implementation = NotifyImplementation()
|
||||||
|
|
||||||
|
|
||||||
|
class PayloadType(Enum):
|
||||||
|
unknown = ''
|
||||||
|
title = 'title'
|
||||||
|
body = 'body'
|
||||||
|
query = '?'
|
||||||
|
close = 'close'
|
||||||
|
|
||||||
|
|
||||||
class OnlyWhen(Enum):
|
class OnlyWhen(Enum):
|
||||||
unset = ''
|
unset = ''
|
||||||
always = 'always'
|
always = 'always'
|
||||||
@@ -141,7 +149,7 @@ def parse_osc_99(raw: str, log_warnings: bool = True) -> NotificationCommand:
|
|||||||
cmd = NotificationCommand()
|
cmd = NotificationCommand()
|
||||||
metadata, payload = raw.partition(';')[::2]
|
metadata, payload = raw.partition(';')[::2]
|
||||||
payload_is_encoded = False
|
payload_is_encoded = False
|
||||||
payload_type = 'title'
|
payload_type = PayloadType.title
|
||||||
if metadata:
|
if metadata:
|
||||||
for part in metadata.split(':'):
|
for part in metadata.split(':'):
|
||||||
try:
|
try:
|
||||||
@@ -151,7 +159,10 @@ def parse_osc_99(raw: str, log_warnings: bool = True) -> NotificationCommand:
|
|||||||
log_error('Malformed OSC 99: metadata is not key=value pairs')
|
log_error('Malformed OSC 99: metadata is not key=value pairs')
|
||||||
return cmd
|
return cmd
|
||||||
if k == 'p':
|
if k == 'p':
|
||||||
payload_type = v
|
try:
|
||||||
|
payload_type = PayloadType(v)
|
||||||
|
except ValueError:
|
||||||
|
payload_type = PayloadType.unknown
|
||||||
elif k == 'i':
|
elif k == 'i':
|
||||||
cmd.identifier = sanitize_id(v)
|
cmd.identifier = sanitize_id(v)
|
||||||
elif k == 'e':
|
elif k == 'e':
|
||||||
@@ -177,14 +188,15 @@ def parse_osc_99(raw: str, log_warnings: bool = True) -> NotificationCommand:
|
|||||||
elif k == 'u':
|
elif k == 'u':
|
||||||
with suppress(Exception):
|
with suppress(Exception):
|
||||||
cmd.urgency = Urgency(int(v))
|
cmd.urgency = Urgency(int(v))
|
||||||
if payload_type == '?':
|
if payload_type is PayloadType.query:
|
||||||
actions = ','.join(x.name for x in Action)
|
actions = ','.join(x.value for x in Action)
|
||||||
when = ','.join(x.name for x in OnlyWhen if x.value)
|
when = ','.join(x.value for x in OnlyWhen if x.value)
|
||||||
urgency = ','.join(str(x.value) for x in Urgency)
|
urgency = ','.join(str(x.value) for x in Urgency)
|
||||||
i = f'i={sanitize_id(cmd.identifier or "0")}:'
|
i = f'i={sanitize_id(cmd.identifier or "0")}:'
|
||||||
raise QueryResponse(f'99;{i}p=?;a={actions}:o={when}:u={urgency}')
|
p = ','.join(x.value for x in PayloadType if x.value)
|
||||||
|
raise QueryResponse(f'99;{i}p=?;a={actions}:o={when}:u={urgency}:p={p}')
|
||||||
|
|
||||||
if payload_type in ('body', 'title'):
|
if payload_type in (PayloadType.title, PayloadType.body):
|
||||||
if payload_is_encoded:
|
if payload_is_encoded:
|
||||||
try:
|
try:
|
||||||
payload = standard_b64decode(payload).decode('utf-8')
|
payload = standard_b64decode(payload).decode('utf-8')
|
||||||
@@ -192,7 +204,7 @@ def parse_osc_99(raw: str, log_warnings: bool = True) -> NotificationCommand:
|
|||||||
if log_warnings:
|
if log_warnings:
|
||||||
log_error('Malformed OSC 99: payload is not base64 encoded UTF-8 text')
|
log_error('Malformed OSC 99: payload is not base64 encoded UTF-8 text')
|
||||||
return NotificationCommand()
|
return NotificationCommand()
|
||||||
if payload_type == 'title':
|
if payload_type is PayloadType.title:
|
||||||
cmd.title = payload
|
cmd.title = payload
|
||||||
else:
|
else:
|
||||||
cmd.body = payload
|
cmd.body = payload
|
||||||
|
|||||||
@@ -601,11 +601,11 @@ class TestParser(BaseTest):
|
|||||||
reset()
|
reset()
|
||||||
h('i=xyz:p=?')
|
h('i=xyz:p=?')
|
||||||
self.assertFalse(notifications)
|
self.assertFalse(notifications)
|
||||||
self.ae(query_responses, ['99;i=xyz:p=?;a=focus,report:o=always,unfocused,invisible:u=0,1,2'])
|
self.ae(query_responses, ['99;i=xyz:p=?;a=focus,report:o=always,unfocused,invisible:u=0,1,2:p=title,body,?,close'])
|
||||||
reset()
|
reset()
|
||||||
h('p=?')
|
h('p=?')
|
||||||
self.assertFalse(notifications)
|
self.assertFalse(notifications)
|
||||||
self.ae(query_responses, ['99;i=0:p=?;a=focus,report:o=always,unfocused,invisible:u=0,1,2'])
|
self.ae(query_responses, ['99;i=0:p=?;a=focus,report:o=always,unfocused,invisible:u=0,1,2:p=title,body,?,close'])
|
||||||
|
|
||||||
def test_dcs_codes(self):
|
def test_dcs_codes(self):
|
||||||
s = self.create_screen()
|
s = self.create_screen()
|
||||||
|
|||||||
Reference in New Issue
Block a user