diff --git a/build.zig b/build.zig index 32fd07eb1..876eb2cec 100644 --- a/build.zig +++ b/build.zig @@ -213,8 +213,6 @@ pub fn build(b: *std.Build) !void { exe_options.addOption(renderer.Impl, "renderer", renderer_impl); exe_options.addOption(bool, "libadwaita", libadwaita); - createRGBNames(b); - // Exe if (exe_) |exe| { exe.root_module.addOptions("build_options", exe_options); @@ -222,8 +220,6 @@ pub fn build(b: *std.Build) !void { // Add the shared dependencies _ = try addDeps(b, exe, static); - addRGBNames(exe); - // If we're in NixOS but not in the shell environment then we issue // a warning because the rpath may not be setup properly. const is_nixos = is_nixos: { @@ -465,8 +461,6 @@ pub fn build(b: *std.Build) !void { lib.linkLibC(); lib.root_module.addOptions("build_options", exe_options); - addRGBNames(lib); - // Create a single static lib with all our dependencies merged var lib_list = try addDeps(b, lib, true); try lib_list.append(lib.getEmittedBin()); @@ -496,8 +490,6 @@ pub fn build(b: *std.Build) !void { lib.linkLibC(); lib.root_module.addOptions("build_options", exe_options); - addRGBNames(lib); - // Create a single static lib with all our dependencies merged var lib_list = try addDeps(b, lib, true); try lib_list.append(lib.getEmittedBin()); @@ -612,8 +604,6 @@ pub fn build(b: *std.Build) !void { .target = b.resolveTargetQuery(wasm_crosstarget), }); - addRGBNames(main_test); - main_test.root_module.addOptions("build_options", exe_options); _ = try addDeps(b, main_test, true); test_step.dependOn(&main_test.step); @@ -650,8 +640,6 @@ pub fn build(b: *std.Build) !void { .filter = test_filter, }); - addRGBNames(main_test); - { if (emit_test_exe) b.installArtifact(main_test); _ = try addDeps(b, main_test, true); @@ -930,45 +918,6 @@ fn addDeps( return static_libs; } -var generate_rgb_names: *std.Build.Step.Run = undefined; -var generate_rgb_names_output: std.Build.LazyPath = undefined; - -fn createRGBNames(b: *std.Build) void { - const gen = b.addExecutable( - .{ - .name = "generate-rgb-names", - .root_source_file = .{ - .path = "src/generate_rgb_names.zig", - }, - .target = b.host, - }, - ); - - const rgb = b.dependency("rgb", .{}); - - gen.root_module.addAnonymousImport( - "rgb", - .{ - .root_source_file = .{ - .path = rgb.builder.pathFromRoot("rgb.txt"), - }, - }, - ); - - generate_rgb_names = b.addRunArtifact(gen); - generate_rgb_names_output = generate_rgb_names.captureStdOut(); -} - -fn addRGBNames(exe: *std.Build.Step.Compile) void { - exe.step.dependOn(&generate_rgb_names.step); - exe.root_module.addAnonymousImport( - "rgb_names", - .{ - .root_source_file = generate_rgb_names_output, - }, - ); -} - fn benchSteps( b: *std.Build, target: std.Build.ResolvedTarget, diff --git a/build.zig.zon b/build.zig.zon index b55b1cba5..c1472894d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -48,9 +48,5 @@ .url = "https://github.com/mbadolato/iTerm2-Color-Schemes/archive/53acae071801e0de6ed160315869abb9bdaf20fa.tar.gz", .hash = "12201575c5a2b21c2e110593773040cddcd357544038092d18bd98fc5a2141354bbd", }, - .rgb = .{ - .url = "https://gitlab.freedesktop.org/xorg/app/rgb/-/archive/master/rgb-master.tar.gz", - .hash = "12201ecce35845b829edf31f5b1b751b24efe6bdc20a8acf06f5c0f2bd83fdd69158", - }, }, } diff --git a/src/config/Config.zig b/src/config/Config.zig index e274550f5..a852fcef7 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -20,7 +20,6 @@ const Key = @import("key.zig").Key; const KeyValue = @import("key.zig").Value; const ErrorList = @import("ErrorList.zig"); const MetricModifier = fontpkg.face.Metrics.Modifier; -const RGBName = @import("rgb_names").RGBName; const log = std.log.scoped(.config); @@ -2139,13 +2138,16 @@ pub const Color = packed struct(u24) { return .{ .r = self.r, .g = self.g, .b = self.b }; } - pub fn parseCLI(input: ?[]const u8) !Color { - if (input == null) return error.ValueRequred; - if (RGBName.fromString(input.?)) |name| { - const rgb = name.toRGB(); - return Color{ .r = rgb.r, .g = rgb.g, .b = rgb.b }; - } - return fromHex(input.?); + pub fn parseCLI(input_: ?[]const u8) !Color { + const input = input_ orelse return error.ValueRequred; + + if (terminal.x11_color.map.get(input)) |rgb| return .{ + .r = rgb.r, + .g = rgb.g, + .b = rgb.b, + }; + + return fromHex(input); } /// Deep copy of the struct. Required by Config. @@ -2195,7 +2197,7 @@ pub const Color = packed struct(u24) { try testing.expectEqual(Color{ .r = 255, .g = 255, .b = 255 }, try Color.fromHex("FFFFFF")); } - test "fromName" { + test "parseCLI from name" { try std.testing.expectEqual(Color{ .r = 0, .g = 0, .b = 0 }, try Color.parseCLI("black")); } }; diff --git a/src/generate_rgb_names.zig b/src/generate_rgb_names.zig deleted file mode 100644 index c60aa34da..000000000 --- a/src/generate_rgb_names.zig +++ /dev/null @@ -1,120 +0,0 @@ -const std = @import("std"); -const rgb = @embedFile("rgb"); - -const RGB = struct { - r: u8, - g: u8, - b: u8, -}; - -pub fn main() !void { - var gpa = std.heap.GeneralPurposeAllocator(.{}){}; - var arena = std.heap.ArenaAllocator.init(gpa.allocator()); - const alloc = arena.allocator(); - - const stdout_file = std.io.getStdOut().writer(); - var bw = std.io.bufferedWriter(stdout_file); - const stdout = bw.writer(); - - var set = std.StringHashMap(RGB).init(alloc); - defer set.deinit(); - var list = std.ArrayList([]const u8).init(alloc); - defer list.deinit(); - - try stdout.writeAll( - \\// THIS FILE IS AUTO-GENERATED! DO NOT MAKE ANY CHANGES! - \\ - \\const std = @import("std"); - \\ - \\pub const RGB = struct { - \\ r: u8, - \\ g: u8, - \\ b: u8, - \\}; - \\ - \\/// RGB color names, taken from the X11 rgb.txt file. - \\pub const RGBName = enum { - \\ - \\ const Self = @This(); - \\ - \\ - ); - - var iter = std.mem.splitScalar(u8, rgb, '\n'); - while (iter.next()) |line| { - if (line.len < 12) continue; - const r = try std.fmt.parseInt(u8, std.mem.trim(u8, line[0..3], &std.ascii.whitespace), 10); - const g = try std.fmt.parseInt(u8, std.mem.trim(u8, line[4..7], &std.ascii.whitespace), 10); - const b = try std.fmt.parseInt(u8, std.mem.trim(u8, line[8..11], &std.ascii.whitespace), 10); - var n = try alloc.alloc(u8, line[12..].len); - defer alloc.free(n); - var i: usize = 0; - for (line[12..]) |c| { - if (std.ascii.isWhitespace(c)) continue; - n[i] = std.ascii.toLower(c); - i += 1; - } - const m = try alloc.dupe(u8, n[0..i]); - if (set.get(m) == null) { - try set.put(m, RGB{ .r = r, .g = g, .b = b }); - try list.append(m); - try stdout.print(" {s},\n", .{ - m, - }); - } - } - - try stdout.writeAll( - \\ - \\ pub fn fromString(str: []const u8) ?Self { - \\ const max = 64; - \\ var n: [max]u8 = undefined; - \\ var i: usize = 0; - \\ for (str, 0..) |c, j| { - \\ if (std.ascii.isWhitespace(c)) continue; - \\ n[i] = std.ascii.toLower(c); - \\ i += 1; - \\ if (i == max) { - \\ if (j >= str.len - 1) std.log.warn("color name '{s}' longer than {d} characters", .{str, max}); - \\ break; - \\ } - \\ } - \\ return std.meta.stringToEnum(Self, n[0..i]); - \\ } - \\ - \\ pub fn toRGB(self: Self) RGB { - \\ return switch(self) { - \\ - ); - - for (list.items) |name| { - if (set.get(name)) |value| { - try stdout.print(" .{s} => RGB{{ .r = {d}, .g = {d}, .b = {d} }},\n", .{ name, value.r, value.g, value.b }); - } - } - - try stdout.writeAll( - \\ }; - \\ } - \\}; - \\ - \\test "RGBName" { - \\ try std.testing.expectEqual(null, RGBName.fromString("nosuchcolor")); - \\ try std.testing.expectEqual(RGBName.white, RGBName.fromString("white")); - \\ try std.testing.expectEqual(RGBName.mediumspringgreen, RGBName.fromString("medium spring green")); - \\ try std.testing.expectEqual(RGBName.forestgreen, RGBName.fromString("ForestGreen")); - \\ - \\ try std.testing.expectEqual(RGB{ .r = 0, .g = 0, .b = 0 }, RGBName.black.toRGB()); - \\ try std.testing.expectEqual(RGB{ .r = 255, .g = 0, .b = 0 }, RGBName.red.toRGB()); - \\ try std.testing.expectEqual(RGB{ .r = 0, .g = 255, .b = 0 }, RGBName.green.toRGB()); - \\ try std.testing.expectEqual(RGB{ .r = 0, .g = 0, .b = 255 }, RGBName.blue.toRGB()); - \\ try std.testing.expectEqual(RGB{ .r = 255, .g = 255, .b = 255 }, RGBName.white.toRGB()); - \\ try std.testing.expectEqual(RGB{ .r = 124, .g = 252, .b = 0 }, RGBName.lawngreen.toRGB()); - \\ try std.testing.expectEqual(RGB{ .r = 0, .g = 250, .b = 154 }, RGBName.mediumspringgreen.toRGB()); - \\ try std.testing.expectEqual(RGB{ .r = 34, .g = 139, .b = 34 }, RGBName.forestgreen.toRGB()); - \\} - \\ - ); - - try bw.flush(); -}