mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
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:
@ -158,6 +158,9 @@ pub const Command = union(enum) {
|
|||||||
/// End a hyperlink (OSC 8)
|
/// End a hyperlink (OSC 8)
|
||||||
hyperlink_end: void,
|
hyperlink_end: void,
|
||||||
|
|
||||||
|
/// Show GUI message Box (OSC 9;2)
|
||||||
|
show_message_box: []const u8,
|
||||||
|
|
||||||
/// Set progress state (OSC 9;4)
|
/// Set progress state (OSC 9;4)
|
||||||
progress: struct {
|
progress: struct {
|
||||||
state: ProgressState,
|
state: ProgressState,
|
||||||
@ -353,6 +356,7 @@ pub const Parser = struct {
|
|||||||
osc_9,
|
osc_9,
|
||||||
|
|
||||||
// ConEmu specific substates
|
// ConEmu specific substates
|
||||||
|
conemu_message_box,
|
||||||
conemu_progress_prestate,
|
conemu_progress_prestate,
|
||||||
conemu_progress_state,
|
conemu_progress_state,
|
||||||
conemu_progress_prevalue,
|
conemu_progress_prevalue,
|
||||||
@ -777,6 +781,9 @@ pub const Parser = struct {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.osc_9 => switch (c) {
|
.osc_9 => switch (c) {
|
||||||
|
'2' => {
|
||||||
|
self.state = .conemu_message_box;
|
||||||
|
},
|
||||||
'4' => {
|
'4' => {
|
||||||
self.state = .conemu_progress_prestate;
|
self.state = .conemu_progress_prestate;
|
||||||
},
|
},
|
||||||
@ -788,6 +795,17 @@ pub const Parser = struct {
|
|||||||
else => self.showDesktopNotification(),
|
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) {
|
.conemu_progress_prestate => switch (c) {
|
||||||
';' => {
|
';' => {
|
||||||
self.command = .{ .progress = .{
|
self.command = .{ .progress = .{
|
||||||
@ -1662,6 +1680,57 @@ test "OSC: show desktop notification with title" {
|
|||||||
try testing.expectEqualStrings(cmd.show_desktop_notification.body, "Body");
|
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" {
|
test "OSC: OSC9 progress set" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
|
@ -1605,7 +1605,7 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
} else log.warn("unimplemented OSC callback: {}", .{cmd});
|
} else log.warn("unimplemented OSC callback: {}", .{cmd});
|
||||||
},
|
},
|
||||||
|
|
||||||
.progress => {
|
.progress, .show_message_box => {
|
||||||
log.warn("unimplemented OSC callback: {}", .{cmd});
|
log.warn("unimplemented OSC callback: {}", .{cmd});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user