Skip to content

Commit

Permalink
termio: prevent responses to non-query OSC 21 sequences (#5770)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rockorager authored Feb 15, 2025
2 parents b975f1e + 09fbf09 commit 29f25ae
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/termio/stream_handler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1517,14 +1519,16 @@ pub const StreamHandler = struct {
}
}

try writer.writeAll(request.terminator.string());

self.messageWriter(.{
.write_alloc = .{
.alloc = self.alloc,
.data = try buf.toOwnedSlice(),
},
});
// 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
Expand Down

0 comments on commit 29f25ae

Please sign in to comment.