osc 9: allow single character notifications

pull/8396/head
Jeffrey C. Ollie 2025-08-25 19:23:52 -05:00
parent a471bac782
commit 3320a081b4
No known key found for this signature in database
GPG Key ID: 6F86035A6D97044E
1 changed files with 21 additions and 2 deletions

View File

@ -1212,6 +1212,11 @@ pub const Parser = struct {
self.temp_state = .{ .str = &self.command.show_desktop_notification.body };
self.state = .string;
// Set as complete as we've already seen one character that should be
// part of the notification. If we wait for another character to set
// `complete` when the state is `.string` we won't be able to send any
// single character notifications.
self.complete = true;
}
fn prepAllocableString(self: *Parser) void {
@ -2836,8 +2841,22 @@ test "OSC: show desktop notification" {
const cmd = p.end('\x1b').?;
try testing.expect(cmd == .show_desktop_notification);
try testing.expectEqualStrings(cmd.show_desktop_notification.title, "");
try testing.expectEqualStrings(cmd.show_desktop_notification.body, "Hello world");
try testing.expectEqualStrings("", cmd.show_desktop_notification.title);
try testing.expectEqualStrings("Hello world", cmd.show_desktop_notification.body);
}
test "OSC: show single character desktop notification" {
const testing = std.testing;
var p: Parser = .init();
const input = "9;H";
for (input) |ch| p.next(ch);
const cmd = p.end('\x1b').?;
try testing.expect(cmd == .show_desktop_notification);
try testing.expectEqualStrings("", cmd.show_desktop_notification.title);
try testing.expectEqualStrings("H", cmd.show_desktop_notification.body);
}
test "OSC: show desktop notification with title" {