Skip to content

Commit 45298f1

Browse files
committed
ControlProtocol(feat): Add MESSAGE and CONFIG_ERROR notification types
why: Complete coverage of all tmux control mode notification types per analysis of tmux source code (control-notify.c, cfg.c). what: - Add MESSAGE and CONFIG_ERROR to NotificationKind enum - Parse %message notifications (from display-message command) - Parse %config-error notifications (from config file errors) - Add test fixtures for both notification types
1 parent 3555911 commit 45298f1

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/libtmux/_internal/engines/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class NotificationKind(enum.Enum):
9999
CONTINUE = enum.auto()
100100
SUBSCRIPTION_CHANGED = enum.auto()
101101
EXIT = enum.auto()
102+
MESSAGE = enum.auto()
103+
CONFIG_ERROR = enum.auto()
102104
RAW = enum.auto()
103105

104106

src/libtmux/_internal/engines/control_protocol.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ def _parse_notification(line: str, parts: list[str]) -> Notification:
155155
data = {"name": parts[1], "type": parts[2], "value": " ".join(parts[3:])}
156156
elif tag == "%exit":
157157
kind = NotificationKind.EXIT
158+
elif tag == "%message" and len(parts) >= 2:
159+
kind = NotificationKind.MESSAGE
160+
data = {"text": " ".join(parts[1:])}
161+
elif tag == "%config-error" and len(parts) >= 2:
162+
kind = NotificationKind.CONFIG_ERROR
163+
data = {"error": " ".join(parts[1:])}
158164

159165
return Notification(kind=kind, when=now, raw=line, data=data)
160166

tests/test_engine_protocol.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ def test_control_protocol_skips_unexpected_begin() -> None:
191191
expected_kind=NotificationKind.PASTE_BUFFER_DELETED,
192192
expected_subset={"name": "buf1"},
193193
),
194+
NotificationFixture(
195+
test_id="message",
196+
line="%message Hello world from tmux",
197+
expected_kind=NotificationKind.MESSAGE,
198+
expected_subset={"text": "Hello world from tmux"},
199+
),
200+
NotificationFixture(
201+
test_id="config_error",
202+
line="%config-error /home/user/.tmux.conf:10: unknown option",
203+
expected_kind=NotificationKind.CONFIG_ERROR,
204+
expected_subset={"error": "/home/user/.tmux.conf:10: unknown option"},
205+
),
194206
]
195207

196208

0 commit comments

Comments
 (0)