authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-06-02 18:11:16+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-02 17:35:34-04:00
logd74180c373274bc545992c2a96a8e7618f8bd52c
treeb8188915feaecc6596d816455a96dcc78e6b653d
parent85eb5a3069c132388191e9531802ccfd993737f1

Replace YES_COLOR with CLICOLOR_FORCE

Instead of introducing YES_COLOR, a completely new standard, into the mix it might make more sense to instead tag along with the CLICOLOR_FORCE env var, which dates back to at least 2000 with FreeBSD 4.1.1 and which is supported by tools like CMake. <https://bixense.com/clicolors/>

6 files changed, 14 insertions(+), 8 deletions(-)

lib/compiler/build_runner.zig+1-1
......@@ -285,7 +285,7 @@ pub fn main() !void {
285285 const ttyconf = get_tty_conf(color, stderr);
286286 switch (ttyconf) {
287287 .no_color => try graph.env_map.put("NO_COLOR", "1"),
288 .escape_codes => try graph.env_map.put("YES_COLOR", "1"),
288 .escape_codes => try graph.env_map.put("CLICOLOR_FORCE", "1"),
289289 .windows_api => {},
290290 }
291291
lib/std/io/tty.zig+2-2
......@@ -7,13 +7,13 @@ const native_os = builtin.os.tag;
77
88/// Detect suitable TTY configuration options for the given file (commonly stdout/stderr).
99/// This includes feature checks for ANSI escape codes and the Windows console API, as well as
10/// respecting the `NO_COLOR` and `YES_COLOR` environment variables to override the default.
10/// respecting the `NO_COLOR` and `CLICOLOR_FORCE` environment variables to override the default.
1111pub fn detectConfig(file: File) Config {
1212 const force_color: ?bool = if (builtin.os.tag == .wasi)
1313 null // wasi does not support environment variables
1414 else if (process.hasEnvVarConstant("NO_COLOR"))
1515 false
16 else if (process.hasEnvVarConstant("YES_COLOR"))
16 else if (process.hasEnvVarConstant("CLICOLOR_FORCE"))
1717 true
1818 else
1919 null;
lib/std/zig.zig+1
......@@ -1060,6 +1060,7 @@ pub const EnvVar = enum {
10601060 ZIG_DEBUG_CMD,
10611061 CC,
10621062 NO_COLOR,
1063 CLICOLOR_FORCE,
10631064 XDG_CACHE_HOME,
10641065 HOME,
10651066
src/main.zig+8-3
......@@ -994,11 +994,16 @@ fn buildOutputType(
994994 .native_system_include_paths = &.{},
995995 };
996996
997 // before arg parsing, check for the NO_COLOR environment variable
998 // if it exists, default the color setting to .off
997 // before arg parsing, check for the NO_COLOR and CLICOLOR_FORCE environment variables
998 // if set, default the color setting to .off or .on, respectively
999999 // explicit --color arguments will still override this setting.
10001000 // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162
1001 var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet()) .off else .auto;
1001 var color: Color = if (native_os == .wasi or EnvVar.NO_COLOR.isSet())
1002 .off
1003 else if (EnvVar.CLICOLOR_FORCE.isSet())
1004 .on
1005 else
1006 .auto;
10021007
10031008 switch (arg_mode) {
10041009 .build, .translate_c, .zig_test, .run => {
test/src/StackTrace.zig+1-1
......@@ -61,7 +61,7 @@ fn addExpect(
6161 });
6262
6363 const run = b.addRunArtifact(exe);
64 run.removeEnvironmentVariable("YES_COLOR");
64 run.removeEnvironmentVariable("CLICOLOR_FORCE");
6565 run.setEnvironmentVariable("NO_COLOR", "1");
6666 run.expectExitCode(1);
6767 run.expectStdOutEqual("");
tools/doctest.zig+1-1
......@@ -104,7 +104,7 @@ fn printOutput(
104104 tmp_dir_path: []const u8,
105105) !void {
106106 var env_map = try process.getEnvMap(arena);
107 try env_map.put("YES_COLOR", "1");
107 try env_map.put("CLICOLOR_FORCE", "1");
108108
109109 const host = try std.zig.system.resolveTargetQuery(.{});
110110 const obj_ext = builtin.object_format.fileExt(builtin.cpu.arch);