| author | |
| committer | |
| log | d74180c373274bc545992c2a96a8e7618f8bd52c |
| tree | b8188915feaecc6596d816455a96dcc78e6b653d |
| parent | 85eb5a3069c132388191e9531802ccfd993737f1 |
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 { | ... | @@ -285,7 +285,7 @@ pub fn main() !void { |
| 285 | const ttyconf = get_tty_conf(color, stderr); | 285 | const ttyconf = get_tty_conf(color, stderr); |
| 286 | switch (ttyconf) { | 286 | switch (ttyconf) { |
| 287 | .no_color => try graph.env_map.put("NO_COLOR", "1"), | 287 | .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"), |
| 289 | .windows_api => {}, | 289 | .windows_api => {}, |
| 290 | } | 290 | } |
| 291 | 291 |
lib/std/io/tty.zig+2-2| ... | @@ -7,13 +7,13 @@ const native_os = builtin.os.tag; | ... | @@ -7,13 +7,13 @@ const native_os = builtin.os.tag; |
| 7 | 7 | ||
| 8 | /// Detect suitable TTY configuration options for the given file (commonly stdout/stderr). | 8 | /// Detect suitable TTY configuration options for the given file (commonly stdout/stderr). |
| 9 | /// This includes feature checks for ANSI escape codes and the Windows console API, as well as | 9 | /// 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. |
| 11 | pub fn detectConfig(file: File) Config { | 11 | pub fn detectConfig(file: File) Config { |
| 12 | const force_color: ?bool = if (builtin.os.tag == .wasi) | 12 | const force_color: ?bool = if (builtin.os.tag == .wasi) |
| 13 | null // wasi does not support environment variables | 13 | null // wasi does not support environment variables |
| 14 | else if (process.hasEnvVarConstant("NO_COLOR")) | 14 | else if (process.hasEnvVarConstant("NO_COLOR")) |
| 15 | false | 15 | false |
| 16 | else if (process.hasEnvVarConstant("YES_COLOR")) | 16 | else if (process.hasEnvVarConstant("CLICOLOR_FORCE")) |
| 17 | true | 17 | true |
| 18 | else | 18 | else |
| 19 | null; | 19 | null; |
lib/std/zig.zig+1| ... | @@ -1060,6 +1060,7 @@ pub const EnvVar = enum { | ... | @@ -1060,6 +1060,7 @@ pub const EnvVar = enum { |
| 1060 | ZIG_DEBUG_CMD, | 1060 | ZIG_DEBUG_CMD, |
| 1061 | CC, | 1061 | CC, |
| 1062 | NO_COLOR, | 1062 | NO_COLOR, |
| 1063 | CLICOLOR_FORCE, | ||
| 1063 | XDG_CACHE_HOME, | 1064 | XDG_CACHE_HOME, |
| 1064 | HOME, | 1065 | HOME, |
| 1065 | 1066 |
src/main.zig+8-3| ... | @@ -994,11 +994,16 @@ fn buildOutputType( | ... | @@ -994,11 +994,16 @@ fn buildOutputType( |
| 994 | .native_system_include_paths = &.{}, | 994 | .native_system_include_paths = &.{}, |
| 995 | }; | 995 | }; |
| 996 | 996 | ||
| 997 | // before arg parsing, check for the NO_COLOR environment variable | 997 | // before arg parsing, check for the NO_COLOR and CLICOLOR_FORCE environment variables |
| 998 | // if it exists, default the color setting to .off | 998 | // if set, default the color setting to .off or .on, respectively |
| 999 | // explicit --color arguments will still override this setting. | 999 | // explicit --color arguments will still override this setting. |
| 1000 | // Disable color on WASI per https://github.com/WebAssembly/WASI/issues/162 | 1000 | // 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; | ||
| 1002 | 1007 | ||
| 1003 | switch (arg_mode) { | 1008 | switch (arg_mode) { |
| 1004 | .build, .translate_c, .zig_test, .run => { | 1009 | .build, .translate_c, .zig_test, .run => { |
test/src/StackTrace.zig+1-1| ... | @@ -61,7 +61,7 @@ fn addExpect( | ... | @@ -61,7 +61,7 @@ fn addExpect( |
| 61 | }); | 61 | }); |
| 62 | 62 | ||
| 63 | const run = b.addRunArtifact(exe); | 63 | const run = b.addRunArtifact(exe); |
| 64 | run.removeEnvironmentVariable("YES_COLOR"); | 64 | run.removeEnvironmentVariable("CLICOLOR_FORCE"); |
| 65 | run.setEnvironmentVariable("NO_COLOR", "1"); | 65 | run.setEnvironmentVariable("NO_COLOR", "1"); |
| 66 | run.expectExitCode(1); | 66 | run.expectExitCode(1); |
| 67 | run.expectStdOutEqual(""); | 67 | run.expectStdOutEqual(""); |
tools/doctest.zig+1-1| ... | @@ -104,7 +104,7 @@ fn printOutput( | ... | @@ -104,7 +104,7 @@ fn printOutput( |
| 104 | tmp_dir_path: []const u8, | 104 | tmp_dir_path: []const u8, |
| 105 | ) !void { | 105 | ) !void { |
| 106 | var env_map = try process.getEnvMap(arena); | 106 | var env_map = try process.getEnvMap(arena); |
| 107 | try env_map.put("YES_COLOR", "1"); | 107 | try env_map.put("CLICOLOR_FORCE", "1"); |
| 108 | 108 | ||
| 109 | const host = try std.zig.system.resolveTargetQuery(.{}); | 109 | const host = try std.zig.system.resolveTargetQuery(.{}); |
| 110 | const obj_ext = builtin.object_format.fileExt(builtin.cpu.arch); | 110 | const obj_ext = builtin.object_format.fileExt(builtin.cpu.arch); |