From c3bdbe4911359038ee20dbd6198b6b82c1cbe6c8 Mon Sep 17 00:00:00 2001 From: namedkitten Date: Sat, 11 Jul 2020 15:56:03 +0100 Subject: [PATCH] Add more build options. --- build.zig | 15 ++++++++++++++- src/formatting/colour.zig | 7 +++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index 632292b..cd22ac9 100644 --- a/build.zig +++ b/build.zig @@ -4,7 +4,20 @@ const Builder = @import("std").build.Builder; pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const exe = b.addExecutable("zar", "src/main.zig"); - exe.addBuildOption(bool, "terminal_version", false); + const disable_colour = b.option( + bool, + "disable_colour", + "no colour", + ) orelse false; + const terminal_version = b.option( + bool, + "terminal_version", + "terminal-only version", + ) orelse false; + exe.addBuildOption(bool, "terminal_version", terminal_version); + exe.addBuildOption(bool, "disable_colour", disable_colour); + + exe.strip = true; exe.addPackage(.{ .name = "interfaces", .path = "deps/interfaces/interface.zig", diff --git a/src/formatting/colour.zig b/src/formatting/colour.zig index e9f87d1..795f1db 100644 --- a/src/formatting/colour.zig +++ b/src/formatting/colour.zig @@ -1,6 +1,7 @@ const std = @import("std"); const eql = std.mem.eql; const terminal_version = @import("build_options").terminal_version; +const disable_colour = @import("build_options").disable_colour; const TextColour = "#D8DEE9"; const DarkerTextColour = "#E5E9F0"; @@ -18,9 +19,9 @@ const TerminalResetColour = "\u{001b}[37m"; const TerminalTextColour = TerminalResetColour; const TerminalDarkerTextColour = TerminalResetColour; const TerminalDarkestTextColour = TerminalResetColour; -const TerminalAccentLightColour = "\u{001b}[38;5;26m"; +const TerminalAccentLightColour = "\u{001b}[38;5;38m"; const TerminalAccentMediumColour = "\u{001b}[38;5;32m"; -const TerminalAccentDarkColour = "\u{001b}[38;5;38m"; +const TerminalAccentDarkColour = "\u{001b}[38;5;26m"; const TerminalRedColour = "\u{001b}[31m"; const TerminalOrangeColour = "\u{001b}[31;1m"; const TerminalYellowColour = "\u{001b}[33m"; @@ -28,6 +29,8 @@ const TerminalGreenColour = "\u{001b}[32m"; const TerminalPurpleColour = "\u{001b}[35m"; pub fn colour(alloc: *std.mem.Allocator, clr: []const u8, str: []const u8) ![]const u8 { + if (disable_colour) return str; + if (clr[0] == '#' or clr[0] == '\u{001b}') { if (terminal_version) { return try std.fmt.allocPrint(alloc, "{}{}" ++ TerminalResetColour, .{ clr, str });