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 library itself.

supportsAnsiEscapeCodes

Threaded.supportsAnsiEscapeCodes
fn supportsAnsiEscapeCodes(t: *Threaded, file: File) Io.Cancelable!bool

File

lib/std/Io/Threaded.zig:8885

Code

fn supportsAnsiEscapeCodes(t: *Threaded, file: File) Io.Cancelable!bool {
    if (is_windows) {
        var get_console_mode = windows.CONSOLE.USER_IO.GET_MODE;
        return switch ((try deviceIoControl(&.{
            .file = .{
                .handle = windows.peb().ProcessParameters.ConsoleHandle,
                .flags = .{ .nonblocking = false },
            },
            .code = windows.IOCTL.CONDRV.ISSUE_USER_IO,
            .in = @ptrCast(&get_console_mode.request(file, 0, .{}, 0, .{})),
        })).u.Status) {
            .SUCCESS => get_console_mode.Data & windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0,
            .CANCELLED => unreachable,
            .INVALID_HANDLE => isCygwinPty(file),
            else => false,
        };
    }

    if (native_os == .wasi) {
        // WASI sanitizes stdout when fd is a tty so ANSI escape codes
        // will not be interpreted as actual cursor commands, and
        // stderr is always sanitized.

        return false;
    }

    if (try isTty(file)) {
        if (file.handle == posix.STDOUT_FILENO or file.handle == posix.STDERR_FILENO) {
            t.scanEnviron();
            if (t.environ.string.TERM) |term| {
                if (std.mem.eql(u8, term, "dumb")) {
                    return false;
                }
            }
        }

        return true;
    }

    return false;
}