termio: prevent responses to non-query OSC 21 sequences

The Ghostty implementation of OSC 21 (Kitty color protocol) currently
responds to *all* OSC 21 sequences. It should not respond to a set, nor
a reset command. Fix the implementation so that we only respond if a
query was received.
This commit is contained in:
Tim Culverhouse
2025-02-14 18:55:26 -06:00
committed by Mitchell Hashimoto
parent f458d48f9b
commit 196bc55757

View File

@ -1418,11 +1418,13 @@ pub const StreamHandler = struct {
var buf = std.ArrayList(u8).init(self.alloc);
defer buf.deinit();
const writer = buf.writer();
try writer.writeAll("\x1b]21");
for (request.list.items) |item| {
switch (item) {
.query => |key| {
// If the writer buffer is empty, we need to write our prefix
if (buf.items.len == 0) try writer.writeAll("\x1b]21");
const color: terminal.color.RGB = switch (key) {
.palette => |palette| self.terminal.color_palette.colors[palette],
.special => |special| switch (special) {
@ -1517,14 +1519,16 @@ pub const StreamHandler = struct {
}
}
// If we had any writes to our buffer, we queue them now
if (buf.items.len > 0) {
try writer.writeAll(request.terminator.string());
self.messageWriter(.{
.write_alloc = .{
.alloc = self.alloc,
.data = try buf.toOwnedSlice(),
},
});
}
// Note: we don't have to do a queueRender here because every
// processed stream will queue a render once it is done processing