From 09fbf096d32c70bab3a42d45c051071904727a4e Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 14 Feb 2025 18:55:26 -0600 Subject: [PATCH] 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. --- src/termio/stream_handler.zig | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/termio/stream_handler.zig b/src/termio/stream_handler.zig index 849e5c107f..e9bb353fba 100644 --- a/src/termio/stream_handler.zig +++ b/src/termio/stream_handler.zig @@ -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 { } } - 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