Implement some more environment functions for WASI.

This commit is contained in:
Brendan Burns
2023-01-06 08:40:16 -08:00
committed by GitHub
parent 7a2d7ff628
commit 24b4e643f4
3 changed files with 35 additions and 18 deletions

View File

@@ -110,27 +110,28 @@ pub fn getSelfDebugInfo() !*DebugInfo {
}
pub fn detectTTYConfig(file: std.fs.File) TTY.Config {
if (process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
if (builtin.os.tag == .wasi) {
// Per https://github.com/WebAssembly/WASI/issues/162 ANSI codes
// aren't currently supported.
return .no_color;
} else if (process.hasEnvVarConstant("ZIG_DEBUG_COLOR")) {
return .escape_codes;
} else if (process.hasEnvVarConstant("NO_COLOR")) {
return .no_color;
} else {
if (file.supportsAnsiEscapeCodes()) {
return .escape_codes;
} else if (native_os == .windows and file.isTty()) {
var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE) {
// TODO: Should this return an error instead?
return .no_color;
}
return .{ .windows_api = .{
.handle = file.handle,
.reset_attributes = info.wAttributes,
} };
} else {
} else if (file.supportsAnsiEscapeCodes()) {
return .escape_codes;
} else if (native_os == .windows and file.isTty()) {
var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE) {
// TODO: Should this return an error instead?
return .no_color;
}
return .{ .windows_api = .{
.handle = file.handle,
.reset_attributes = info.wAttributes,
} };
}
return .no_color;
}
/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.