feat: parse ConEmu OSC9;2 (#4447)

This PR implements support for the [ConEmu OSC9;2 escape
sequence](https://conemu.github.io/en/AnsiEscapeCodes.html#OSC_Operating_system_commands).

| Sequence | Description |
| - | - |
ESC ] 9 ; 2 ; ”txt“ ST | Show GUI MessageBox ( txt ) for any purposes.
This commit is contained in:
Mitchell Hashimoto
2025-01-04 14:37:01 -08:00
committed by GitHub
2 changed files with 70 additions and 1 deletions

View File

@ -158,6 +158,9 @@ pub const Command = union(enum) {
/// End a hyperlink (OSC 8)
hyperlink_end: void,
/// Show GUI message Box (OSC 9;2)
show_message_box: []const u8,
/// Set progress state (OSC 9;4)
progress: struct {
state: ProgressState,
@ -353,6 +356,7 @@ pub const Parser = struct {
osc_9,
// ConEmu specific substates
conemu_message_box,
conemu_progress_prestate,
conemu_progress_state,
conemu_progress_prevalue,
@ -777,6 +781,9 @@ pub const Parser = struct {
},
.osc_9 => switch (c) {
'2' => {
self.state = .conemu_message_box;
},
'4' => {
self.state = .conemu_progress_prestate;
},
@ -788,6 +795,17 @@ pub const Parser = struct {
else => self.showDesktopNotification(),
},
.conemu_message_box => switch (c) {
';' => {
self.command = .{ .show_message_box = undefined };
self.temp_state = .{ .str = &self.command.show_message_box };
self.buf_start = self.buf_idx;
self.complete = true;
self.prepAllocableString();
},
else => self.state = .invalid,
},
.conemu_progress_prestate => switch (c) {
';' => {
self.command = .{ .progress = .{
@ -1662,6 +1680,57 @@ test "OSC: show desktop notification with title" {
try testing.expectEqualStrings(cmd.show_desktop_notification.body, "Body");
}
test "OSC: conemu message box" {
const testing = std.testing;
var p: Parser = .{};
const input = "9;2;hello world";
for (input) |ch| p.next(ch);
const cmd = p.end('\x1b').?;
try testing.expect(cmd == .show_message_box);
try testing.expectEqualStrings("hello world", cmd.show_message_box);
}
test "OSC: conemu message box invalid input" {
const testing = std.testing;
var p: Parser = .{};
const input = "9;2";
for (input) |ch| p.next(ch);
const cmd = p.end('\x1b');
try testing.expect(cmd == null);
}
test "OSC: conemu message box empty message" {
const testing = std.testing;
var p: Parser = .{};
const input = "9;2;";
for (input) |ch| p.next(ch);
const cmd = p.end('\x1b').?;
try testing.expect(cmd == .show_message_box);
try testing.expectEqualStrings("", cmd.show_message_box);
}
test "OSC: conemu message box spaces only message" {
const testing = std.testing;
var p: Parser = .{};
const input = "9;2; ";
for (input) |ch| p.next(ch);
const cmd = p.end('\x1b').?;
try testing.expect(cmd == .show_message_box);
try testing.expectEqualStrings(" ", cmd.show_message_box);
}
test "OSC: OSC9 progress set" {
const testing = std.testing;

View File

@ -1605,7 +1605,7 @@ pub fn Stream(comptime Handler: type) type {
} else log.warn("unimplemented OSC callback: {}", .{cmd});
},
.progress => {
.progress, .show_message_box => {
log.warn("unimplemented OSC callback: {}", .{cmd});
},
}