From 469c88c0c6534e9633f8596402d4a64ceb9b71ae Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 21 Nov 2023 09:58:09 -0600 Subject: [PATCH] osc: fix OSC4 response When reporting colors via OSC4, the index must also be reported. --- src/termio/Exec.zig | 73 +++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 79da8eef8..c800c6589 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -2278,30 +2278,57 @@ const StreamHandler = struct { var msg: termio.Message = .{ .write_small = .{} }; const resp = switch (self.osc_color_report_format) { - .@"16-bit" => try std.fmt.bufPrint( - &msg.write_small.data, - "\x1B]{s};rgb:{x:0>4}/{x:0>4}/{x:0>4}{s}", - .{ - kind.code(), - @as(u16, color.r) * 257, - @as(u16, color.g) * 257, - @as(u16, color.b) * 257, - terminator.string(), - }, - ), - - .@"8-bit" => try std.fmt.bufPrint( - &msg.write_small.data, - "\x1B]{s};rgb:{x:0>2}/{x:0>2}/{x:0>2}{s}", - .{ - kind.code(), - @as(u16, color.r), - @as(u16, color.g), - @as(u16, color.b), - terminator.string(), - }, - ), + .@"16-bit" => switch (kind) { + .palette => |i| try std.fmt.bufPrint( + &msg.write_small.data, + "\x1B]{s};{d};rgb:{x:0>4}/{x:0>4}/{x:0>4}{s}", + .{ + kind.code(), + i, + @as(u16, color.r) * 257, + @as(u16, color.g) * 257, + @as(u16, color.b) * 257, + terminator.string(), + }, + ), + else => try std.fmt.bufPrint( + &msg.write_small.data, + "\x1B]{s};rgb:{x:0>4}/{x:0>4}/{x:0>4}{s}", + .{ + kind.code(), + @as(u16, color.r) * 257, + @as(u16, color.g) * 257, + @as(u16, color.b) * 257, + terminator.string(), + }, + ), + }, + .@"8-bit" => switch (kind) { + .palette => |i| try std.fmt.bufPrint( + &msg.write_small.data, + "\x1B]{s};{d};rgb:{x:0>2}/{x:0>2}/{x:0>2}{s}", + .{ + kind.code(), + i, + @as(u16, color.r), + @as(u16, color.g), + @as(u16, color.b), + terminator.string(), + }, + ), + else => try std.fmt.bufPrint( + &msg.write_small.data, + "\x1B]{s};rgb:{x:0>2}/{x:0>2}/{x:0>2}{s}", + .{ + kind.code(), + @as(u16, color.r), + @as(u16, color.g), + @as(u16, color.b), + terminator.string(), + }, + ), + }, .none => unreachable, // early return above }; msg.write_small.len = @intCast(resp.len);