From e95fdd2f21bda187c3a521417243d7280110f6a1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 23 Mar 2026 10:15:01 -0700 Subject: [PATCH] terminal: handle CRLF line endings in rgb.txt parsing The X11 color map parser in x11_color.zig uses @embedFile to load rgb.txt at comptime, then splits on \n. On Windows, git may check out rgb.txt with CRLF line endings, leaving a trailing \r on each line. This caused color names to be stored as e.g. "white\r" instead of "white", so all X11 color lookups failed at runtime. Strip trailing \r from each line before parsing. Also mark rgb.txt as -text in .gitattributes to prevent line ending conversion in future checkouts. --- .gitattributes | 1 + src/terminal/x11_color.zig | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index 9158b3979..2e976e5f9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12,3 +12,4 @@ src/font/nerd_font_attributes.zig linguist-generated=true src/font/nerd_font_codepoint_tables.py linguist-generated=true src/font/res/** linguist-vendored src/terminal/res/** linguist-vendored +src/terminal/res/rgb.txt -text diff --git a/src/terminal/x11_color.zig b/src/terminal/x11_color.zig index 95dcb76db..97f3a7ce4 100644 --- a/src/terminal/x11_color.zig +++ b/src/terminal/x11_color.zig @@ -25,12 +25,18 @@ fn colorMap() ColorMap { // of our unit tests will catch it. var iter = std.mem.splitScalar(u8, data, '\n'); var i: usize = 0; - while (iter.next()) |line| { + while (iter.next()) |raw_line| { + // Trim \r so this works with both LF and CRLF line endings, + // since git may convert rgb.txt to CRLF on Windows checkouts. + const line = if (raw_line.len > 0 and raw_line[raw_line.len - 1] == '\r') + raw_line[0 .. raw_line.len - 1] + else + raw_line; if (line.len == 0) continue; const r = try std.fmt.parseInt(u8, std.mem.trim(u8, line[0..3], " "), 10); const g = try std.fmt.parseInt(u8, std.mem.trim(u8, line[4..7], " "), 10); const b = try std.fmt.parseInt(u8, std.mem.trim(u8, line[8..11], " "), 10); - const name = std.mem.trim(u8, line[12..], " \t\n"); + const name = std.mem.trim(u8, line[12..], " \t"); kvs[i] = .{ name, .{ .r = r, .g = g, .b = b } }; i += 1; } -- 2.51.2