| author | |
| committer | |
| log | 93e54f2354aa1b3de797a7ca5572bfa8c0f733f1 |
| tree | 93fbbe87a2876a424e3fa267014cc109e3a8de26 |
| parent | 64f0059cd33b571d6cf91df45f4cb2e0af9c0742 |
| parent | e45d24c0de29eb6668e56ea927e15505674833a6 |
| signature |
std.io.tty: cleanup detectConfig4 files changed, 22 insertions(+), 17 deletions(-)
doc/docgen.zig+1-1| ... | @@ -1305,7 +1305,7 @@ fn genHtml( | ... | @@ -1305,7 +1305,7 @@ fn genHtml( |
| 1305 | defer root_node.end(); | 1305 | defer root_node.end(); |
| 1306 | 1306 | ||
| 1307 | var env_map = try process.getEnvMap(allocator); | 1307 | var env_map = try process.getEnvMap(allocator); |
| 1308 | try env_map.put("ZIG_DEBUG_COLOR", "1"); | 1308 | try env_map.put("YES_COLOR", "1"); |
| 1309 | 1309 | ||
| 1310 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); | 1310 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); |
| 1311 | const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe, opt_zig_lib_dir); | 1311 | const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe, opt_zig_lib_dir); |
lib/build_runner.zig+1-1| ... | @@ -282,7 +282,7 @@ pub fn main() !void { | ... | @@ -282,7 +282,7 @@ pub fn main() !void { |
| 282 | const ttyconf = get_tty_conf(color, stderr); | 282 | const ttyconf = get_tty_conf(color, stderr); |
| 283 | switch (ttyconf) { | 283 | switch (ttyconf) { |
| 284 | .no_color => try builder.env_map.put("NO_COLOR", "1"), | 284 | .no_color => try builder.env_map.put("NO_COLOR", "1"), |
| 285 | .escape_codes => try builder.env_map.put("ZIG_DEBUG_COLOR", "1"), | 285 | .escape_codes => try builder.env_map.put("YES_COLOR", "1"), |
| 286 | .windows_api => {}, | 286 | .windows_api => {}, |
| 287 | } | 287 | } |
| 288 | 288 |
lib/std/io/tty.zig+19-14| ... | @@ -7,29 +7,34 @@ const native_os = builtin.os.tag; | ... | @@ -7,29 +7,34 @@ 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` environment variable. | 10 | /// respecting the `NO_COLOR` and `YES_COLOR` environment variables to override the default. |
| 11 | pub fn detectConfig(file: File) Config { | 11 | pub fn detectConfig(file: File) Config { |
| 12 | if (builtin.os.tag == .wasi) { | 12 | const force_color: ?bool = if (builtin.os.tag == .wasi) |
| 13 | // Per https://github.com/WebAssembly/WASI/issues/162 ANSI codes | 13 | null // wasi does not support environment variables |
| 14 | // aren't currently supported. | 14 | else if (process.hasEnvVarConstant("NO_COLOR")) |
| 15 | return .no_color; | 15 | false |
| 16 | } else if (process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) { | 16 | else if (process.hasEnvVarConstant("YES_COLOR")) |
| 17 | return .escape_codes; | 17 | true |
| 18 | } else if (process.hasEnvVarConstant("NO_COLOR")) { | 18 | else |
| 19 | return .no_color; | 19 | null; |
| 20 | } else if (file.supportsAnsiEscapeCodes()) { | 20 | |
| 21 | return .escape_codes; | 21 | if (force_color == false) return .no_color; |
| 22 | } else if (native_os == .windows and file.isTty()) { | 22 | |
| 23 | if (native_os == .windows and file.isTty()) { | ||
| 23 | var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; | 24 | var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined; |
| 24 | if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE) { | 25 | if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE) { |
| 25 | // TODO: Should this return an error instead? | 26 | return if (force_color == true) .escape_codes else .no_color; |
| 26 | return .no_color; | ||
| 27 | } | 27 | } |
| 28 | return .{ .windows_api = .{ | 28 | return .{ .windows_api = .{ |
| 29 | .handle = file.handle, | 29 | .handle = file.handle, |
| 30 | .reset_attributes = info.wAttributes, | 30 | .reset_attributes = info.wAttributes, |
| 31 | } }; | 31 | } }; |
| 32 | } | 32 | } |
| 33 | |||
| 34 | if (force_color == true or file.supportsAnsiEscapeCodes()) { | ||
| 35 | return .escape_codes; | ||
| 36 | } | ||
| 37 | |||
| 33 | return .no_color; | 38 | return .no_color; |
| 34 | } | 39 | } |
| 35 | 40 |
test/src/StackTrace.zig+1-1| ... | @@ -81,7 +81,7 @@ fn addExpect( | ... | @@ -81,7 +81,7 @@ fn addExpect( |
| 81 | }); | 81 | }); |
| 82 | 82 | ||
| 83 | const run = b.addRunArtifact(exe); | 83 | const run = b.addRunArtifact(exe); |
| 84 | run.removeEnvironmentVariable("ZIG_DEBUG_COLOR"); | 84 | run.removeEnvironmentVariable("YES_COLOR"); |
| 85 | run.setEnvironmentVariable("NO_COLOR", "1"); | 85 | run.setEnvironmentVariable("NO_COLOR", "1"); |
| 86 | run.expectExitCode(1); | 86 | run.expectExitCode(1); |
| 87 | run.expectStdOutEqual(""); | 87 | run.expectStdOutEqual(""); |