mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-18 21:40:29 +00:00
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.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user