Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › Io › Terminal › Mode › detect Public Function detect Doc Source Public Function std.Io.Terminal.Mode.detect
pub fn detect (io : Io , file : File , NO_COLOR : bool , CLICOLOR_FORCE : bool ) Io .Cancelable !Mode Params io : Io file : File NO_COLOR : bool CLICOLOR_FORCE : bool File Io/Terminal.zig: 57
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 pub fn detect (io : Io , file : File , NO_COLOR : bool , CLICOLOR_FORCE : bool ) Io .Cancelable !Mode {
const force_color : ?bool = if (NO_COLOR ) false else if (CLICOLOR_FORCE ) true else null ;
if (force_color == false ) return .no_color ;
if (file .enableAnsiEscapeCodes (io )) |_ | {
return .escape_codes ;
} else |err | switch (err ) {
error .Canceled => |e | return e ,
error .NotTerminalDevice , error .Unexpected => {},
}
if (is_windows and try file .isTty (io )) {
var get_console_info = std .os .windows .CONSOLE .USER_IO .GET_SCREEN_BUFFER_INFO ;
switch (try get_console_info .operate (io , file )) {
.SUCCESS => return .{ .windows_api = .{
.io = io ,
.file = file ,
.reset_attributes = get_console_info .Data .wAttributes ,
} },
else => {},
}
}
return if (force_color == true ) .escape_codes else .no_color ;
}
Detect suitable TTY configuration options for the given file (commonly stdout/stderr).
Will attempt to enable ANSI escape code support if necessary/possible.
NO_COLORindicates whether "NO_COLOR" environment variable is present and non-empty.CLICOLOR_FORCEindicates whether "CLICOLOR_FORCE" environment variable is present and non-empty.