pub const Color = enum pub fn terminalMode(color: Color) ?Io.Terminal.Modepub fn settingFromEnvironment(environ_map: *const std.process.Environ.Map) ColorDetermine the preference for color or no color based on the NO_COLOR and CLICOLOR_FORCE environment variables. Color is always disabled on WASI per https://github.com/WebAssembly/WASI/issues/162
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90pub const Color = enum {
/// Auto-detect whether stream supports terminal colors.
auto,
/// Force-enable colors.
off,
/// Suppress colors.
on,
pub fn terminalMode(color: Color) ?Io.Terminal.Mode {
return switch (color) {
.auto => null,
.on => .escape_codes,
.off => .no_color,
};
}
/// Determine the preference for color or no color based on the NO_COLOR and
/// CLICOLOR_FORCE environment variables. Color is always disabled on WASI per
/// https://github.com/WebAssembly/WASI/issues/162
pub fn settingFromEnvironment(environ_map: *const std.process.Environ.Map) Color {
return if (builtin.os.tag == .wasi or EnvVar.NO_COLOR.isSet(environ_map))
.off
else if (EnvVar.CLICOLOR_FORCE.isSet(environ_map))
.on
else
.auto;
}
}