mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
parse ConEmu OSC9;3 (#4644)
This PR implements support for the [ConEmu OSC9;3 escape sequence](https://conemu.github.io/en/AnsiEscapeCodes.html#OSC_Operating_system_commands). | Sequence | Description | | - | - | ESC ] 9 ; 3 ; ”txt“ ST | Change ConEmu Tab to txt. Set empty string to return original Tab text #3125
This commit is contained in:
@ -208,6 +208,20 @@ pub const VTEvent = struct {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.Union => |info| {
|
||||||
|
const Tag = info.tag_type orelse @compileError("Unions must have a tag");
|
||||||
|
const tag_name = @tagName(@as(Tag, v));
|
||||||
|
inline for (info.fields) |field| {
|
||||||
|
if (std.mem.eql(u8, field.name, tag_name)) {
|
||||||
|
if (field.type == void) {
|
||||||
|
break try md.put("data", tag_name);
|
||||||
|
} else {
|
||||||
|
break try encodeMetadataSingle(alloc, md, tag_name, @field(v, field.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
@compileLog(T);
|
@compileLog(T);
|
||||||
@compileError("unsupported type, see log");
|
@compileError("unsupported type, see log");
|
||||||
|
@ -161,6 +161,12 @@ pub const Command = union(enum) {
|
|||||||
/// Show GUI message Box (OSC 9;2)
|
/// Show GUI message Box (OSC 9;2)
|
||||||
show_message_box: []const u8,
|
show_message_box: []const u8,
|
||||||
|
|
||||||
|
/// Change ConEmu tab (OSC 9;3)
|
||||||
|
change_conemu_tab_title: union(enum) {
|
||||||
|
reset: void,
|
||||||
|
value: []const u8,
|
||||||
|
},
|
||||||
|
|
||||||
/// Set progress state (OSC 9;4)
|
/// Set progress state (OSC 9;4)
|
||||||
progress: struct {
|
progress: struct {
|
||||||
state: ProgressState,
|
state: ProgressState,
|
||||||
@ -357,6 +363,8 @@ pub const Parser = struct {
|
|||||||
|
|
||||||
// ConEmu specific substates
|
// ConEmu specific substates
|
||||||
conemu_message_box,
|
conemu_message_box,
|
||||||
|
conemu_tab,
|
||||||
|
conemu_tab_txt,
|
||||||
conemu_progress_prestate,
|
conemu_progress_prestate,
|
||||||
conemu_progress_state,
|
conemu_progress_state,
|
||||||
conemu_progress_prevalue,
|
conemu_progress_prevalue,
|
||||||
@ -784,6 +792,9 @@ pub const Parser = struct {
|
|||||||
'2' => {
|
'2' => {
|
||||||
self.state = .conemu_message_box;
|
self.state = .conemu_message_box;
|
||||||
},
|
},
|
||||||
|
'3' => {
|
||||||
|
self.state = .conemu_tab;
|
||||||
|
},
|
||||||
'4' => {
|
'4' => {
|
||||||
self.state = .conemu_progress_prestate;
|
self.state = .conemu_progress_prestate;
|
||||||
},
|
},
|
||||||
@ -806,6 +817,23 @@ pub const Parser = struct {
|
|||||||
else => self.state = .invalid,
|
else => self.state = .invalid,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.conemu_tab => switch (c) {
|
||||||
|
';' => {
|
||||||
|
self.state = .conemu_tab_txt;
|
||||||
|
self.command = .{ .change_conemu_tab_title = .{ .reset = {} } };
|
||||||
|
self.buf_start = self.buf_idx;
|
||||||
|
self.complete = true;
|
||||||
|
},
|
||||||
|
else => self.state = .invalid,
|
||||||
|
},
|
||||||
|
|
||||||
|
.conemu_tab_txt => {
|
||||||
|
self.command = .{ .change_conemu_tab_title = .{ .value = undefined } };
|
||||||
|
self.temp_state = .{ .str = &self.command.change_conemu_tab_title.value };
|
||||||
|
self.complete = true;
|
||||||
|
self.prepAllocableString();
|
||||||
|
},
|
||||||
|
|
||||||
.conemu_progress_prestate => switch (c) {
|
.conemu_progress_prestate => switch (c) {
|
||||||
';' => {
|
';' => {
|
||||||
self.command = .{ .progress = .{
|
self.command = .{ .progress = .{
|
||||||
@ -1731,6 +1759,59 @@ test "OSC: conemu message box spaces only message" {
|
|||||||
try testing.expectEqualStrings(" ", cmd.show_message_box);
|
try testing.expectEqualStrings(" ", cmd.show_message_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "OSC: conemu change tab title" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var p: Parser = .{};
|
||||||
|
|
||||||
|
const input = "9;3;foo bar";
|
||||||
|
for (input) |ch| p.next(ch);
|
||||||
|
|
||||||
|
const cmd = p.end('\x1b').?;
|
||||||
|
try testing.expect(cmd == .change_conemu_tab_title);
|
||||||
|
try testing.expectEqualStrings("foo bar", cmd.change_conemu_tab_title.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "OSC: conemu change tab reset title" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var p: Parser = .{};
|
||||||
|
|
||||||
|
const input = "9;3;";
|
||||||
|
for (input) |ch| p.next(ch);
|
||||||
|
|
||||||
|
const cmd = p.end('\x1b').?;
|
||||||
|
|
||||||
|
const expected_command: Command = .{ .change_conemu_tab_title = .{ .reset = {} } };
|
||||||
|
try testing.expectEqual(expected_command, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "OSC: conemu change tab spaces only title" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var p: Parser = .{};
|
||||||
|
|
||||||
|
const input = "9;3; ";
|
||||||
|
for (input) |ch| p.next(ch);
|
||||||
|
|
||||||
|
const cmd = p.end('\x1b').?;
|
||||||
|
|
||||||
|
try testing.expect(cmd == .change_conemu_tab_title);
|
||||||
|
try testing.expectEqualStrings(" ", cmd.change_conemu_tab_title.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "OSC: conemu change tab invalid input" {
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
var p: Parser = .{};
|
||||||
|
|
||||||
|
const input = "9;3";
|
||||||
|
for (input) |ch| p.next(ch);
|
||||||
|
|
||||||
|
const cmd = p.end('\x1b');
|
||||||
|
try testing.expect(cmd == null);
|
||||||
|
}
|
||||||
|
|
||||||
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, .show_message_box => {
|
.progress, .show_message_box, .change_conemu_tab_title => {
|
||||||
log.warn("unimplemented OSC callback: {}", .{cmd});
|
log.warn("unimplemented OSC callback: {}", .{cmd});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user