-
Notifications
You must be signed in to change notification settings - Fork 1
/
is_color_supported.ts
36 lines (32 loc) 路 1.04 KB
/
is_color_supported.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
let supported = true;
const permissions = await Promise.all([
Deno.permissions.query({ name: "env", variable: "TERM" }),
Deno.permissions.query({ name: "env", variable: "CI" }),
Deno.permissions.query({ name: "env", variable: "FORCE_COLOR" }),
]);
if (permissions.every((permission) => permission.state === "granted")) {
supported =
// terminal is not dumb
(Deno.isatty(1) && Deno.env.get("TERM") !== "dumb") ||
// default support in CI systems which haven't disabled colors
!!Deno.env.get("CI") ||
// colors are forced by the environment
!!Deno.env.get("FORCE_COLOR");
}
/**
* Check for color support.
*
* Requires the `--allow-env` flag to be passed to Deno.
*/
export function isColorSupported() {
// Exit early if the user has disabled colors.
if (Deno.noColor || Deno.args.includes("--no-color")) {
return false;
}
return (
// forced by args used when calling this script
Deno.args.includes("--color") ||
// support colors on windows by default
Deno.build.os === "windows" || supported
);
}