From 97df179b0466eba8adf46d45d37b3b20dbd85c29 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 24 Jun 2023 15:04:33 -0700 Subject: [PATCH] terminfo: switch to semicolon SGR 48 to prevent render issues --- src/terminal/Parser.zig | 29 +++++++++++++++++++++++++++++ src/terminal/sgr.zig | 10 ++++++++++ src/terminal/stream.zig | 2 +- src/terminfo/ghostty.zig | 6 ++++-- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/terminal/Parser.zig b/src/terminal/Parser.zig index 0c3d8ca73..abfbc0efb 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -531,6 +531,35 @@ test "csi: SGR ESC [ 38 : 2 m" { } } +test "csi: SGR ESC [ 48 : 2 m" { + var p = init(); + _ = p.next(0x1B); + for ("[48:2:240:143:104") |c| { + const a = p.next(c); + try testing.expect(a[0] == null); + try testing.expect(a[1] == null); + try testing.expect(a[2] == null); + } + + { + const a = p.next('m'); + try testing.expect(p.state == .ground); + try testing.expect(a[0] == null); + try testing.expect(a[1].? == .csi_dispatch); + try testing.expect(a[2] == null); + + const d = a[1].?.csi_dispatch; + try testing.expect(d.final == 'm'); + try testing.expect(d.sep == .colon); + try testing.expect(d.params.len == 5); + try testing.expectEqual(@as(u16, 48), d.params[0]); + try testing.expectEqual(@as(u16, 2), d.params[1]); + try testing.expectEqual(@as(u16, 240), d.params[2]); + try testing.expectEqual(@as(u16, 143), d.params[3]); + try testing.expectEqual(@as(u16, 104), d.params[4]); + } +} + test "csi: SGR ESC [4:3m colon" { var p = init(); _ = p.next(0x1B); diff --git a/src/terminal/sgr.zig b/src/terminal/sgr.zig index c7fcda035..865518b8e 100644 --- a/src/terminal/sgr.zig +++ b/src/terminal/sgr.zig @@ -467,6 +467,16 @@ test "sgr: 256 color" { try testing.expect(p.next().? == .@"256_bg"); } +test "sgr: 24-bit bg color" { + { + const v = testParseColon(&[_]u16{ 48, 2, 1, 2, 3 }); + try testing.expect(v == .direct_color_bg); + try testing.expectEqual(@as(u8, 1), v.direct_color_bg.r); + try testing.expectEqual(@as(u8, 2), v.direct_color_bg.g); + try testing.expectEqual(@as(u8, 3), v.direct_color_bg.b); + } +} + test "sgr: underline color" { { const v = testParseColon(&[_]u16{ 58, 2, 1, 2, 3 }); diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index d681992e5..e78b3f457 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -48,7 +48,7 @@ pub fn Stream(comptime Handler: type) type { tracy.value(@intCast(u64, c)); defer tracy.end(); - //log.debug("char: {x}", .{c}); + // log.debug("char: {c}", .{c}); const actions = self.parser.next(c); for (actions) |action_opt| { // if (action_opt) |action| { diff --git a/src/terminfo/ghostty.zig b/src/terminfo/ghostty.zig index 0dbaf7d31..865210155 100644 --- a/src/terminfo/ghostty.zig +++ b/src/terminfo/ghostty.zig @@ -39,7 +39,7 @@ pub const ghostty: Source = .{ .{ .name = "ccc", .value = .{ .boolean = {} } }, // supports changing the window title. - //.{ .name = "hs", .value = .{ .boolean = {} } }, + .{ .name = "hs", .value = .{ .boolean = {} } }, // terminal has a meta key .{ .name = "km", .value = .{ .boolean = {} } }, @@ -155,7 +155,9 @@ pub const ghostty: Source = .{ .{ .name = "rmxx", .value = .{ .string = "\\E[29m" } }, .{ .name = "setab", .value = .{ .string = "\\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m" } }, .{ .name = "setaf", .value = .{ .string = "\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m" } }, - .{ .name = "setrgbb", .value = .{ .string = "\\E[48:2:%p1%d:%p2%d:%p3%dm" } }, + .{ .name = "setrgbb", .value = .{ .string = "\\E[48;2;%p1%d;%p2%d;%p3%dm" } }, + // This causes weird rendering issues, why? + //.{ .name = "setrgbb", .value = .{ .string = "\\E[48:2:%p1%d:%p2%d:%p3%dm" } }, .{ .name = "setrgbf", .value = .{ .string = "\\E[38:2:%p1%d:%p2%d:%p3%dm" } }, .{ .name = "sgr", .value = .{ .string = "%?%p9%t\\E(0%e\\E(B%;\\E[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m" } }, .{ .name = "sgr0", .value = .{ .string = "\\E(B\\E[m" } },