@visulima/is-ansi-color-supported 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## @visulima/is-ansi-color-supported [2.2.0](https://github.com/visulima/visulima/compare/@visulima/is-ansi-color-supported@2.1.0...@visulima/is-ansi-color-supported@2.2.0) (2024-04-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **is-ansi-color-supported:** add support for PM2 process manager ([dd8bb6f](https://github.com/visulima/visulima/commit/dd8bb6f93a9abff12f2a89fd06651559010d586a))
|
|
7
|
+
* **is-ansi-color-support:** updated readme ([38ca0a0](https://github.com/visulima/visulima/commit/38ca0a0fcf2d644bdfa80a324c6b4e16dc5e4afa))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* fixed CLI flags and FORCE_COLOR should precede other color support checks ([d8b524e](https://github.com/visulima/visulima/commit/d8b524e27a28b8818bb306f032e8eb17f1dfb237))
|
|
13
|
+
|
|
1
14
|
## @visulima/is-ansi-color-supported [2.1.0](https://github.com/visulima/visulima/compare/@visulima/is-ansi-color-supported@2.0.2...@visulima/is-ansi-color-supported@2.1.0) (2024-04-09)
|
|
2
15
|
|
|
3
16
|
|
package/README.md
CHANGED
|
@@ -56,6 +56,45 @@ console.log(isStdoutColorSupported()); // 3
|
|
|
56
56
|
console.log(isStderrColorSupported()); // 3
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
## Color support
|
|
60
|
+
|
|
61
|
+
Ansis automatically detects the supported color space:
|
|
62
|
+
|
|
63
|
+
- TrueColor
|
|
64
|
+
- ANSI 256 colors
|
|
65
|
+
- ANSI 16 colors
|
|
66
|
+
- black & white (no color)
|
|
67
|
+
|
|
68
|
+
There is no standard way to detect which color space is supported.
|
|
69
|
+
The most common way to detect color support is to check the `TERM` and `COLORTERM` environment variables.
|
|
70
|
+
CI systems can be detected by checking for the existence of the `CI` and other specifically environment variables.
|
|
71
|
+
Combine that with the knowledge about which operating system the program is running on, and we have a decent enough way to detect colors.
|
|
72
|
+
|
|
73
|
+
| Terminal | ANSI 16<br>colors | ANSI 256<br>colors | True<br>Color | env.<br>TERM | env.<br>COLORTERM | Specifically ENV variables |
|
|
74
|
+
|:---------------------------------|-------------------|:-------------------|:--------------|:--------------:|:-----------------:|:---------------------------------------|
|
|
75
|
+
| Azure CI | ✅ | ❌ | ❌ | dumb | | TF_BUILD<br>AGENT_NAME |
|
|
76
|
+
| GitHub CI | ✅ | ✅ | ✅ | dumb | | CI<br>GITHUB_ACTIONS |
|
|
77
|
+
| GitTea CI | ✅ | ✅ | ✅ | dumb | | CI<br>GITEA_ACTIONS |
|
|
78
|
+
| GitLab CI | ✅ | ❌ | ❌ | dumb | | CI<br>GITLAB_CI |
|
|
79
|
+
| Travis CI | ✅ | ❌ | ❌ | dumb | | TRAVIS |
|
|
80
|
+
| PM2<br>not isTTY | ✅[^1] | ✅[^1] | ✅[^1] | dumb | | PM2_HOME<br>pm_id |
|
|
81
|
+
| JetBrains TeamCity<br>>=2020.1.1 | ✅ | ✅ | ❌ | | | TEAMCITY_VERSION |
|
|
82
|
+
| JetBrains IDEA | ✅ | ✅ | ✅ | xterm-256color | | TERMINAL_EMULATOR='JetBrains-JediTerm' |
|
|
83
|
+
| VS Code | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
|
|
84
|
+
| Windows<br>Terminal | ✅ | ✅ | ✅[^2] | | | |
|
|
85
|
+
| Windows<br>PowerShell | ✅ | ✅ | ✅[^2] | | | |
|
|
86
|
+
| macOS Terminal | ✅ | ✅ | ❌ | xterm-256color | | |
|
|
87
|
+
| iTerm | ✅ | ✅ | ✅ | xterm-256color | truecolor | |
|
|
88
|
+
| Terminal emulator Kitty | ✅ | ✅ | ✅ | xterm-kitty | | |
|
|
89
|
+
|
|
90
|
+
[^1]: Colors supported depends on actual terminal.
|
|
91
|
+
[^2]: The Windows terminal supports true color since Windows 10 revision 14931 (2016-09-21).
|
|
92
|
+
|
|
93
|
+
See also:
|
|
94
|
+
|
|
95
|
+
- [Truecolor Support in Output Devices](https://github.com/termstandard/colors#truecolor-support-in-output-devices).
|
|
96
|
+
- [So you want to render colors in your terminal](https://marvinh.dev/blog/terminal-colors/).
|
|
97
|
+
|
|
59
98
|
## Environment variables
|
|
60
99
|
|
|
61
100
|
To force disable or enable colored output use environment variables `NO_COLOR` and `FORCE_COLOR`.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkVGFXSNOZ_cjs = require('./chunk-VGFXSNOZ.cjs');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var d=a=>{let l=globalThis,R=l.Deno!=null,n=l.process??l.Deno??{},E=n.argv??n.args??[],O=t=>{let _=E.indexOf("--"),S=E.findIndex(A=>t.test(A));return S!==-1&&(_===-1||S<_)},r={};try{r=R?n.env.toObject():n.env??{};}catch{}let p="FORCE_COLOR",m=p in r,i=r[p]?String(r[p]):void 0,T=Object.prototype.toString.call(i).slice(8,-1)==="String",o;if(i==="true"?o=1:i==="false"?o=0:T&&i.length===0?o=1:T&&i.length>0&&(o=Math.min(Number.parseInt(i,10),3)),i!=="true"&&i!=="false"&&o!==void 0&&o<4)return o;if("NO_COLOR"in r||m&&o===0||O(/^-{1,2}(no-color|no-colors|color=false|color=never)$/))return 0;if(O(/^-{1,2}(color=256)$/))return 2;if(O(/^-{1,2}(color=16m|color=full|color=truecolor)$/))return 3;if(O(/^-{1,2}(color|colors|color=true|color=always)$/))return 1;let C=o||0;if("TF_BUILD"in r&&"AGENT_NAME"in r)return 1;if(r.TERM&&/-mono|dumb/i.test(r.TERM))return C;if((R?l.Deno.build.os:n.platform)==="win32")try{let t=(R?l.Deno.osRelease():n.os.release()).split(".");return Number(t[0])>=10&&Number(t[2])>=10586?Number(t[2])>=14931?3:2:1}catch{}if("CI"in r)return "GITHUB_ACTIONS"in r||"GITHUB_WORKFLOW"in r||"GITEA_ACTIONS"in r?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE","GITLAB_CI"].some(t=>t in r)||r.CI_NAME==="codeship"?1:C;if(r.TERMINAL_EMULATOR?.includes("JediTerm"))return 3;if("TEAMCITY_VERSION"in r)return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(r.TEAMCITY_VERSION)?1:0;if(r.COLORTERM==="truecolor")return 3;if(r.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in r){let t=Number.parseInt((r.TERM_PROGRAM_VERSION??"").split(".")[0],10);if(r.TERM_PROGRAM==="iTerm.app")return t>=3?3:2;if(r.TERM_PROGRAM==="Apple_Terminal")return 2}if(/-256(color)?$/i.test(r.TERM))return 2;let c=!1;return R?a==="out"?c=l.Deno.stdout.isTerminal():a==="err"&&(c=l.Deno.stderr.isTerminal()):"PM2_HOME"in r&&"pm_id"in r?c=!0:c=n["std"+a]&&"isTTY"in n["std"+a],c&&/^screen|^tmux|^xterm|^vt[1-5]\d\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(r.TERM)?1:"COLORTERM"in r?1:C},b=()=>d("out"),v=()=>d("err");
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, 'SPACE_16_COLORS', {
|
|
8
8
|
enumerable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupportedFactory","stdName","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version","isTTY","isStdoutColorSupported","isStderrColorSupported"],"mappings":"8DAWA,IAAMA,EAA2BC,GAA8C,CAE3E,IAAMC,EAAQ,WAERC,EAASD,EAAM,MAAQ,KAEvBE,EAA4BF,EAAM,SAAWA,EA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B,KAAK","sourcesContent":["// Some of this code is taken from https://github.com/chalk/supports-color/blob/main/index.js\n// MIT License\n// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nimport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO,SPACE_TRUE_COLORS } from \"./color-spaces\";\nimport type { ColorSupportLevel } from \"./types\";\n\n/**\n * @param {string} stdName The standard name of the stream, either \"err\" or \"out\".\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst isColorSupportedFactory = (stdName: \"err\" | \"out\"): ColorSupportLevel => {\n // eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-explicit-any\n const _this = globalThis as any;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const isDeno = _this.Deno != null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access\n const proc: Record<string, any> = _this.process ?? _this.Deno ?? {};\n // Node -> `argv`, Deno -> `args`\n const argv: string[] = (proc.argv ?? proc.args ?? []) as string[];\n\n /**\n * Detect whether flags exist with `-` or `--` prefix in command-line arguments.\n *\n * @param {RegExp} regex The RegEx to match all possible flags.\n * @return {boolean}\n */\n const oneOfFlags = (regex: RegExp): boolean => {\n const terminatorPosition = argv.indexOf(\"--\");\n\n const position = argv.findIndex((flag) => regex.test(flag));\n\n return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n };\n\n let environment: Record<string, string | undefined> = {};\n\n try {\n // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n environment = isDeno ? proc.env.toObject() : proc.env ?? {};\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n\n const FORCE_COLOR = \"FORCE_COLOR\";\n const hasForceColor = FORCE_COLOR in environment;\n // eslint-disable-next-line security/detect-object-injection\n const forceColorValue = environment[FORCE_COLOR] ? String(environment[FORCE_COLOR]) : undefined;\n const forceColorValueIsString = Object.prototype.toString.call(forceColorValue).slice(8, -1) === \"String\";\n\n let forceColor: ColorSupportLevel = SPACE_MONO;\n\n if (forceColorValue === \"true\") {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValue === \"false\") {\n forceColor = SPACE_MONO;\n } else if (forceColorValueIsString && (forceColorValue as string).length === 0) {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValueIsString && (forceColorValue as string).length > 0) {\n forceColor = Math.min(Number.parseInt(forceColorValue as string, 10), 3) as ColorSupportLevel;\n }\n\n const isForceDisabled =\n // eslint-disable-next-line regexp/no-unused-capturing-group\n \"NO_COLOR\" in environment || (hasForceColor && forceColor === 0) || oneOfFlags(/^-{1,2}(no-color|no-colors|color=false|color=never)$/);\n\n if (isForceDisabled) {\n return SPACE_MONO;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=256)$/)) {\n return SPACE_256_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=16m|color=full|color=truecolor)$/)) {\n return SPACE_TRUE_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n const isForceEnabled = oneOfFlags(/^-{1,2}(color|colors|color=true|color=always)$/);\n\n if (isForceEnabled) {\n return SPACE_16_COLORS;\n }\n\n // note: the order of checks is important\n // many terminals that support truecolor have TERM as `xterm-256colors` but do not set COLORTERM to `truecolor`\n // therefore they can be detected by specific EVN variables\n\n const minColorLevel = forceColor || SPACE_MONO;\n\n // Check for Azure DevOps pipelines.\n // Has to be above the `stream isTTY` check.\n if (\"TF_BUILD\" in environment && \"AGENT_NAME\" in environment) {\n return SPACE_16_COLORS;\n }\n\n const isDumbTerminal: boolean = (environment.TERM && /-mono|dumb/i.test(environment.TERM)) as boolean;\n\n if (isDumbTerminal) {\n return minColorLevel;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if ((isDeno ? _this.Deno.build.os : proc.platform) === \"win32\") {\n try {\n // Deno requires the permission for the access to the operating system, use the `--allow-sys` flag: deno run --allow-sys ./app.js\n\n // Windows 10 build 10586 is the first Windows release that supports 256 colors.\n // Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const osRelease = (isDeno ? _this.Deno.osRelease() : proc.os.release()).split(\".\");\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10_586) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return Number(osRelease[2]) >= 14_931 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n return SPACE_16_COLORS;\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n }\n\n if (\"CI\" in environment) {\n if (\"GITHUB_ACTIONS\" in environment || \"GITHUB_WORKFLOW\" in environment || \"GITEA_ACTIONS\" in environment) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\n [\"TRAVIS\", \"CIRCLECI\", \"APPVEYOR\", \"GITLAB_CI\", \"BUILDKITE\", \"DRONE\", \"GITLAB_CI\"].some((sign) => sign in environment) ||\n environment.CI_NAME === \"codeship\"\n ) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n }\n\n // JetBrains IDEA: JetBrains-JediTerm\n if (environment.TERMINAL_EMULATOR?.includes(\"JediTerm\")) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TEAMCITY_VERSION\" in environment) {\n // https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingMessages\n // eslint-disable-next-line regexp/no-unused-capturing-group\n return /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(environment.TEAMCITY_VERSION as string) ? SPACE_16_COLORS : SPACE_MONO;\n }\n\n if (environment.COLORTERM === \"truecolor\") {\n return SPACE_TRUE_COLORS;\n }\n\n // kitty is GPU based terminal emulator\n if (environment.TERM === \"xterm-kitty\") {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TERM_PROGRAM\" in environment) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const version = Number.parseInt(((environment.TERM_PROGRAM_VERSION as string) ?? \"\").split(\".\")[0] as string, 10);\n\n if (environment.TERM_PROGRAM === \"iTerm.app\") {\n return version >= 3 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n if (environment.TERM_PROGRAM === \"Apple_Terminal\") {\n return SPACE_256_COLORS;\n }\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (/-256(color)?$/i.test(<string>environment.TERM)) {\n return SPACE_256_COLORS;\n }\n\n let isTTY = false;\n\n if (isDeno) {\n if (stdName === \"out\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stdout.isTerminal();\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n } else if (stdName === \"err\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stderr.isTerminal();\n }\n } else {\n isTTY = proc[\"std\" + stdName] && \"isTTY\" in proc[\"std\" + stdName];\n }\n\n if (isTTY && /^screen|^tmux|^xterm|^vt[1-5]\\d\\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(<string>environment.TERM)) {\n return SPACE_16_COLORS;\n }\n\n if (\"COLORTERM\" in environment) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n};\n\nexport const isStdoutColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"out\");\n\nexport const isStderrColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"err\");\n// eslint-disable-next-line import/no-unused-modules\nexport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO,SPACE_TRUE_COLORS } from \"./color-spaces\";\n// eslint-disable-next-line import/no-unused-modules\nexport type { ColorSupportLevel } from \"./types\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupportedFactory","stdName","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version","isTTY","isStdoutColorSupported","isStderrColorSupported"],"mappings":"8DAWA,IAAMA,EAA2BC,GAA8C,CAE3E,IAAMC,EAAQ,WAERC,EAASD,EAAM,MAAQ,KAEvBE,EAA4BF,EAAM,SAAWA,EAAM,MAAQ,CAAC,EAE5DG,EAAkBD,EAAK,MAAQA,EAAK,MAAQ,CAAC,EAQ7CE,EAAcC,GAA2B,CAC3C,IAAMC,EAAqBH,EAAK,QAAQ,IAAI,EAEtCI,EAAWJ,EAAK,UAAWK,GAASH,EAAM,KAAKG,CAAI,CAAC,EAE1D,OAAOD,IAAa,KAAOD,IAAuB,IAAMC,EAAWD,EACvE,EAEIG,EAAkD,CAAC,EAEvD,GAAI,CAGAA,EAAcR,EAASC,EAAK,IAAI,SAAS,EAAIA,EAAK,KAAO,CAAC,CAC9D,MAAQ,CAER,CAEA,IAAMQ,EAAc,cACdC,EAAgBD,KAAeD,EAE/BG,EAAkBH,EAAYC,CAAW,EAAI,OAAOD,EAAYC,CAAW,CAAC,EAAI,OAChFG,EAA0B,OAAO,UAAU,SAAS,KAAKD,CAAe,EAAE,MAAM,EAAG,EAAE,IAAM,SAE7FE,EAYJ,GAVIF,IAAoB,OACpBE,EAAa,EACNF,IAAoB,QAC3BE,EAAa,EACND,GAA4BD,EAA2B,SAAW,EACzEE,EAAa,EACND,GAA4BD,EAA2B,OAAS,IACvEE,EAAa,KAAK,IAAI,OAAO,SAASF,EAA2B,EAAE,EAAG,CAAC,GAGvEA,IAAoB,QAAUA,IAAoB,SAAWE,IAAe,QAAaA,EAAa,EACtG,OAAOA,EAOX,GAFI,aAAcL,GAAgB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,EAAY,eAAiB,iBAC7B,MAAO,EAEf,CAGA,GAAI,iBAAiB,KAAaA,EAAY,IAAI,EAC9C,MAAO,GAGX,IAAIU,EAAQ,GAkBZ,OAhBIlB,EACIF,IAAY,MAEZoB,EAAQnB,EAAM,KAAK,OAAO,WAAW,EAE9BD,IAAY,QAEnBoB,EAAQnB,EAAM,KAAK,OAAO,WAAW,GAElC,aAAcS,GAAe,UAAWA,EAE/CU,EAAQ,GAERA,EAAQjB,EAAK,MAAQH,CAAO,GAAK,UAAWG,EAAK,MAAQH,CAAO,EAGhEoB,GAAS,0EAA0E,KAAaV,EAAY,IAAI,EACzG,EAGP,cAAeA,EACR,EAGJM,CACX,EAEaK,EAAyB,IAAyBtB,EAAwB,KAAK,EAE/EuB,EAAyB,IAAyBvB,EAAwB,KAAK","sourcesContent":["// Some of this code is taken from https://github.com/chalk/supports-color/blob/main/index.js\n// MIT License\n// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nimport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO, SPACE_TRUE_COLORS } from \"./color-spaces\";\nimport type { ColorSupportLevel } from \"./types\";\n\n/**\n * @param {string} stdName The standard name of the stream, either \"err\" or \"out\".\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst isColorSupportedFactory = (stdName: \"err\" | \"out\"): ColorSupportLevel => {\n // eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-explicit-any\n const _this = globalThis as any;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const isDeno = _this.Deno != null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access\n const proc: Record<string, any> = _this.process ?? _this.Deno ?? {};\n // Node -> `argv`, Deno -> `args`\n const argv: string[] = (proc.argv ?? proc.args ?? []) as string[];\n\n /**\n * Detect whether flags exist with `-` or `--` prefix in command-line arguments.\n *\n * @param {RegExp} regex The RegEx to match all possible flags.\n * @return {boolean}\n */\n const oneOfFlags = (regex: RegExp): boolean => {\n const terminatorPosition = argv.indexOf(\"--\");\n\n const position = argv.findIndex((flag) => regex.test(flag));\n\n return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n };\n\n let environment: Record<string, string | undefined> = {};\n\n try {\n // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n environment = isDeno ? proc.env.toObject() : proc.env ?? {};\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n\n const FORCE_COLOR = \"FORCE_COLOR\";\n const hasForceColor = FORCE_COLOR in environment;\n // eslint-disable-next-line security/detect-object-injection\n const forceColorValue = environment[FORCE_COLOR] ? String(environment[FORCE_COLOR]) : undefined;\n const forceColorValueIsString = Object.prototype.toString.call(forceColorValue).slice(8, -1) === \"String\";\n\n let forceColor: ColorSupportLevel | undefined;\n\n if (forceColorValue === \"true\") {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValue === \"false\") {\n forceColor = SPACE_MONO;\n } else if (forceColorValueIsString && (forceColorValue as string).length === 0) {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValueIsString && (forceColorValue as string).length > 0) {\n forceColor = Math.min(Number.parseInt(forceColorValue as string, 10), 3) as ColorSupportLevel;\n }\n\n if (forceColorValue !== \"true\" && forceColorValue !== \"false\" && forceColor !== undefined && forceColor < 4) {\n return forceColor;\n }\n\n const isForceDisabled =\n // eslint-disable-next-line regexp/no-unused-capturing-group\n \"NO_COLOR\" in environment || (hasForceColor && forceColor === 0) || oneOfFlags(/^-{1,2}(no-color|no-colors|color=false|color=never)$/);\n\n if (isForceDisabled) {\n return SPACE_MONO;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=256)$/)) {\n return SPACE_256_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=16m|color=full|color=truecolor)$/)) {\n return SPACE_TRUE_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n const isForceEnabled = oneOfFlags(/^-{1,2}(color|colors|color=true|color=always)$/);\n\n if (isForceEnabled) {\n return SPACE_16_COLORS;\n }\n\n // note: the order of checks is important\n // many terminals that support truecolor have TERM as `xterm-256colors` but do not set COLORTERM to `truecolor`\n // therefore they can be detected by specific EVN variables\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n const minColorLevel = forceColor || SPACE_MONO;\n\n // Check for Azure DevOps pipelines.\n // Has to be above the `stream isTTY` check.\n if (\"TF_BUILD\" in environment && \"AGENT_NAME\" in environment) {\n return SPACE_16_COLORS;\n }\n\n const isDumbTerminal: boolean = (environment.TERM && /-mono|dumb/i.test(environment.TERM)) as boolean;\n\n if (isDumbTerminal) {\n return minColorLevel;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if ((isDeno ? _this.Deno.build.os : proc.platform) === \"win32\") {\n try {\n // Deno requires the permission for the access to the operating system, use the `--allow-sys` flag: deno run --allow-sys ./app.js\n\n // Windows 10 build 10586 is the first Windows release that supports 256 colors.\n // Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const osRelease = (isDeno ? _this.Deno.osRelease() : proc.os.release()).split(\".\");\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10_586) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return Number(osRelease[2]) >= 14_931 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n return SPACE_16_COLORS;\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n }\n\n if (\"CI\" in environment) {\n if (\"GITHUB_ACTIONS\" in environment || \"GITHUB_WORKFLOW\" in environment || \"GITEA_ACTIONS\" in environment) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\n [\"TRAVIS\", \"CIRCLECI\", \"APPVEYOR\", \"GITLAB_CI\", \"BUILDKITE\", \"DRONE\", \"GITLAB_CI\"].some((sign) => sign in environment) ||\n environment.CI_NAME === \"codeship\"\n ) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n }\n\n // JetBrains IDEA: JetBrains-JediTerm\n if (environment.TERMINAL_EMULATOR?.includes(\"JediTerm\")) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TEAMCITY_VERSION\" in environment) {\n // https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingMessages\n // eslint-disable-next-line regexp/no-unused-capturing-group\n return /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(environment.TEAMCITY_VERSION as string) ? SPACE_16_COLORS : SPACE_MONO;\n }\n\n if (environment.COLORTERM === \"truecolor\") {\n return SPACE_TRUE_COLORS;\n }\n\n // kitty is GPU based terminal emulator\n if (environment.TERM === \"xterm-kitty\") {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TERM_PROGRAM\" in environment) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const version = Number.parseInt(((environment.TERM_PROGRAM_VERSION as string) ?? \"\").split(\".\")[0] as string, 10);\n\n if (environment.TERM_PROGRAM === \"iTerm.app\") {\n return version >= 3 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n if (environment.TERM_PROGRAM === \"Apple_Terminal\") {\n return SPACE_256_COLORS;\n }\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (/-256(color)?$/i.test(<string>environment.TERM)) {\n return SPACE_256_COLORS;\n }\n\n let isTTY = false;\n\n if (isDeno) {\n if (stdName === \"out\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stdout.isTerminal();\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n } else if (stdName === \"err\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stderr.isTerminal();\n }\n } else if (\"PM2_HOME\" in environment && \"pm_id\" in environment) {\n // PM2 does not set process.stdout.isTTY, but colors may be supported (depends on actual terminal)\n isTTY = true;\n } else {\n isTTY = proc[\"std\" + stdName] && \"isTTY\" in proc[\"std\" + stdName];\n }\n\n if (isTTY && /^screen|^tmux|^xterm|^vt[1-5]\\d\\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(<string>environment.TERM)) {\n return SPACE_16_COLORS;\n }\n\n if (\"COLORTERM\" in environment) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n};\n\nexport const isStdoutColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"out\");\n\nexport const isStderrColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"err\");\n// eslint-disable-next-line import/no-unused-modules\nexport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO, SPACE_TRUE_COLORS } from \"./color-spaces\";\n// eslint-disable-next-line import/no-unused-modules\nexport type { ColorSupportLevel } from \"./types\";\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { b as SPACE_16_COLORS, c as SPACE_256_COLORS, a as SPACE_MONO, d as SPACE_TRUE_COLORS } from './chunk-ARYGRP3O.js';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var d=a=>{let l=globalThis,R=l.Deno!=null,n=l.process??l.Deno??{},E=n.argv??n.args??[],O=t=>{let _=E.indexOf("--"),S=E.findIndex(A=>t.test(A));return S!==-1&&(_===-1||S<_)},r={};try{r=R?n.env.toObject():n.env??{};}catch{}let p="FORCE_COLOR",m=p in r,i=r[p]?String(r[p]):void 0,T=Object.prototype.toString.call(i).slice(8,-1)==="String",o;if(i==="true"?o=1:i==="false"?o=0:T&&i.length===0?o=1:T&&i.length>0&&(o=Math.min(Number.parseInt(i,10),3)),i!=="true"&&i!=="false"&&o!==void 0&&o<4)return o;if("NO_COLOR"in r||m&&o===0||O(/^-{1,2}(no-color|no-colors|color=false|color=never)$/))return 0;if(O(/^-{1,2}(color=256)$/))return 2;if(O(/^-{1,2}(color=16m|color=full|color=truecolor)$/))return 3;if(O(/^-{1,2}(color|colors|color=true|color=always)$/))return 1;let C=o||0;if("TF_BUILD"in r&&"AGENT_NAME"in r)return 1;if(r.TERM&&/-mono|dumb/i.test(r.TERM))return C;if((R?l.Deno.build.os:n.platform)==="win32")try{let t=(R?l.Deno.osRelease():n.os.release()).split(".");return Number(t[0])>=10&&Number(t[2])>=10586?Number(t[2])>=14931?3:2:1}catch{}if("CI"in r)return "GITHUB_ACTIONS"in r||"GITHUB_WORKFLOW"in r||"GITEA_ACTIONS"in r?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE","GITLAB_CI"].some(t=>t in r)||r.CI_NAME==="codeship"?1:C;if(r.TERMINAL_EMULATOR?.includes("JediTerm"))return 3;if("TEAMCITY_VERSION"in r)return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(r.TEAMCITY_VERSION)?1:0;if(r.COLORTERM==="truecolor")return 3;if(r.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in r){let t=Number.parseInt((r.TERM_PROGRAM_VERSION??"").split(".")[0],10);if(r.TERM_PROGRAM==="iTerm.app")return t>=3?3:2;if(r.TERM_PROGRAM==="Apple_Terminal")return 2}if(/-256(color)?$/i.test(r.TERM))return 2;let c=!1;return R?a==="out"?c=l.Deno.stdout.isTerminal():a==="err"&&(c=l.Deno.stderr.isTerminal()):"PM2_HOME"in r&&"pm_id"in r?c=!0:c=n["std"+a]&&"isTTY"in n["std"+a],c&&/^screen|^tmux|^xterm|^vt[1-5]\d\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(r.TERM)?1:"COLORTERM"in r?1:C},v=()=>d("out"),P=()=>d("err");
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export { P as isStderrColorSupported, v as isStdoutColorSupported };
|
|
6
6
|
//# sourceMappingURL=out.js.map
|
|
7
7
|
//# sourceMappingURL=is-color-supported.server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupportedFactory","stdName","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version","isTTY","isStdoutColorSupported","isStderrColorSupported"],"mappings":"6DAWA,IAAMA,EAA2BC,GAA8C,CAE3E,IAAMC,EAAQ,WAERC,EAASD,EAAM,MAAQ,KAEvBE,EAA4BF,EAAM,SAAWA,EAAM,MAAQ,CAAC,EAE5DG,EAAkBD,EAAK,MAAQA,EAAK,MAAQ,CAAC,EAQ7CE,EAAcC,GAA2B,CAC3C,IAAMC,EAAqBH,EAAK,QAAQ,IAAI,EAEtCI,EAAWJ,EAAK,UAAWK,GAASH,EAAM,KAAKG,CAAI,CAAC,EAE1D,OAAOD,IAAa,KAAOD,IAAuB,IAAMC,EAAWD,EACvE,EAEIG,EAAkD,CAAC,EAEvD,GAAI,CAGAA,EAAcR,EAASC,EAAK,IAAI,SAAS,EAAIA,EAAK,KAAO,CAAC,CAC9D,MAAQ,CAER,CAEA,IAAMQ,EAAc,cACdC,EAAgBD,KAAeD,EAE/BG,EAAkBH,EAAYC,CAAW,EAAI,OAAOD,EAAYC,CAAW,CAAC,EAAI,OAChFG,EAA0B,OAAO,UAAU,SAAS,KAAKD,CAAe,EAAE,MAAM,EAAG,EAAE,IAAM,SAE7FE,EAAgC,EAgBpC,GAdIF,IAAoB,OACpBE,EAAa,EACNF,IAAoB,QAC3BE,EAAa,EACND,GAA4BD,EAA2B,SAAW,EACzEE,EAAa,EACND,GAA4BD,EAA2B,OAAS,IACvEE,EAAa,KAAK,IAAI,OAAO,SAASF,EAA2B,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AAOS,GAAW,EAAI,EAAoB,EAG9C,GAAIT,EAAY,eAAiB,iBAC7B,MAAO,EAEf,CAGA,GAAI,iBAAiB,KAAaA,EAAY,IAAI,EAC9C,MAAO,GAGX,IAAIU,EAAQ,GAeZ,OAbIlB,EACIF,IAAY,MAEZoB,EAAQnB,EAAM,KAAK,OAAO,WAAW,EAE9BD,IAAY,QAEnBoB,EAAQnB,EAAM,KAAK,OAAO,WAAW,GAGzCmB,EAAQjB,EAAK,MAAQH,CAAO,GAAK,UAAWG,EAAK,MAAQH,CAAO,EAGhEoB,GAAS,0EAA0E,KAAaV,EAAY,IAAI,EACzG,EAGP,cAAeA,EACR,EAGJM,CACX,EAEaK,EAAyB,IAAyBtB,EAAwB,KAAK,EAE/EuB,EAAyB,IAAyBvB,EAAwB,KAAK","sourcesContent":["// Some of this code is taken from https://github.com/chalk/supports-color/blob/main/index.js\n// MIT License\n// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nimport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO,SPACE_TRUE_COLORS } from \"./color-spaces\";\nimport type { ColorSupportLevel } from \"./types\";\n\n/**\n * @param {string} stdName The standard name of the stream, either \"err\" or \"out\".\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst isColorSupportedFactory = (stdName: \"err\" | \"out\"): ColorSupportLevel => {\n // eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-explicit-any\n const _this = globalThis as any;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const isDeno = _this.Deno != null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access\n const proc: Record<string, any> = _this.process ?? _this.Deno ?? {};\n // Node -> `argv`, Deno -> `args`\n const argv: string[] = (proc.argv ?? proc.args ?? []) as string[];\n\n /**\n * Detect whether flags exist with `-` or `--` prefix in command-line arguments.\n *\n * @param {RegExp} regex The RegEx to match all possible flags.\n * @return {boolean}\n */\n const oneOfFlags = (regex: RegExp): boolean => {\n const terminatorPosition = argv.indexOf(\"--\");\n\n const position = argv.findIndex((flag) => regex.test(flag));\n\n return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n };\n\n let environment: Record<string, string | undefined> = {};\n\n try {\n // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n environment = isDeno ? proc.env.toObject() : proc.env ?? {};\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n\n const FORCE_COLOR = \"FORCE_COLOR\";\n const hasForceColor = FORCE_COLOR in environment;\n // eslint-disable-next-line security/detect-object-injection\n const forceColorValue = environment[FORCE_COLOR] ? String(environment[FORCE_COLOR]) : undefined;\n const forceColorValueIsString = Object.prototype.toString.call(forceColorValue).slice(8, -1) === \"String\";\n\n let forceColor: ColorSupportLevel = SPACE_MONO;\n\n if (forceColorValue === \"true\") {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValue === \"false\") {\n forceColor = SPACE_MONO;\n } else if (forceColorValueIsString && (forceColorValue as string).length === 0) {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValueIsString && (forceColorValue as string).length > 0) {\n forceColor = Math.min(Number.parseInt(forceColorValue as string, 10), 3) as ColorSupportLevel;\n }\n\n const isForceDisabled =\n // eslint-disable-next-line regexp/no-unused-capturing-group\n \"NO_COLOR\" in environment || (hasForceColor && forceColor === 0) || oneOfFlags(/^-{1,2}(no-color|no-colors|color=false|color=never)$/);\n\n if (isForceDisabled) {\n return SPACE_MONO;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=256)$/)) {\n return SPACE_256_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=16m|color=full|color=truecolor)$/)) {\n return SPACE_TRUE_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n const isForceEnabled = oneOfFlags(/^-{1,2}(color|colors|color=true|color=always)$/);\n\n if (isForceEnabled) {\n return SPACE_16_COLORS;\n }\n\n // note: the order of checks is important\n // many terminals that support truecolor have TERM as `xterm-256colors` but do not set COLORTERM to `truecolor`\n // therefore they can be detected by specific EVN variables\n\n const minColorLevel = forceColor || SPACE_MONO;\n\n // Check for Azure DevOps pipelines.\n // Has to be above the `stream isTTY` check.\n if (\"TF_BUILD\" in environment && \"AGENT_NAME\" in environment) {\n return SPACE_16_COLORS;\n }\n\n const isDumbTerminal: boolean = (environment.TERM && /-mono|dumb/i.test(environment.TERM)) as boolean;\n\n if (isDumbTerminal) {\n return minColorLevel;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if ((isDeno ? _this.Deno.build.os : proc.platform) === \"win32\") {\n try {\n // Deno requires the permission for the access to the operating system, use the `--allow-sys` flag: deno run --allow-sys ./app.js\n\n // Windows 10 build 10586 is the first Windows release that supports 256 colors.\n // Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const osRelease = (isDeno ? _this.Deno.osRelease() : proc.os.release()).split(\".\");\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10_586) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return Number(osRelease[2]) >= 14_931 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n return SPACE_16_COLORS;\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n }\n\n if (\"CI\" in environment) {\n if (\"GITHUB_ACTIONS\" in environment || \"GITHUB_WORKFLOW\" in environment || \"GITEA_ACTIONS\" in environment) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\n [\"TRAVIS\", \"CIRCLECI\", \"APPVEYOR\", \"GITLAB_CI\", \"BUILDKITE\", \"DRONE\", \"GITLAB_CI\"].some((sign) => sign in environment) ||\n environment.CI_NAME === \"codeship\"\n ) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n }\n\n // JetBrains IDEA: JetBrains-JediTerm\n if (environment.TERMINAL_EMULATOR?.includes(\"JediTerm\")) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TEAMCITY_VERSION\" in environment) {\n // https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingMessages\n // eslint-disable-next-line regexp/no-unused-capturing-group\n return /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(environment.TEAMCITY_VERSION as string) ? SPACE_16_COLORS : SPACE_MONO;\n }\n\n if (environment.COLORTERM === \"truecolor\") {\n return SPACE_TRUE_COLORS;\n }\n\n // kitty is GPU based terminal emulator\n if (environment.TERM === \"xterm-kitty\") {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TERM_PROGRAM\" in environment) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const version = Number.parseInt(((environment.TERM_PROGRAM_VERSION as string) ?? \"\").split(\".\")[0] as string, 10);\n\n if (environment.TERM_PROGRAM === \"iTerm.app\") {\n return version >= 3 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n if (environment.TERM_PROGRAM === \"Apple_Terminal\") {\n return SPACE_256_COLORS;\n }\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (/-256(color)?$/i.test(<string>environment.TERM)) {\n return SPACE_256_COLORS;\n }\n\n let isTTY = false;\n\n if (isDeno) {\n if (stdName === \"out\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stdout.isTerminal();\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n } else if (stdName === \"err\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stderr.isTerminal();\n }\n } else {\n isTTY = proc[\"std\" + stdName] && \"isTTY\" in proc[\"std\" + stdName];\n }\n\n if (isTTY && /^screen|^tmux|^xterm|^vt[1-5]\\d\\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(<string>environment.TERM)) {\n return SPACE_16_COLORS;\n }\n\n if (\"COLORTERM\" in environment) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n};\n\nexport const isStdoutColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"out\");\n\nexport const isStderrColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"err\");\n// eslint-disable-next-line import/no-unused-modules\nexport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO,SPACE_TRUE_COLORS } from \"./color-spaces\";\n// eslint-disable-next-line import/no-unused-modules\nexport type { ColorSupportLevel } from \"./types\";\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/is-color-supported.server.ts"],"names":["isColorSupportedFactory","stdName","_this","isDeno","proc","argv","oneOfFlags","regex","terminatorPosition","position","flag","environment","FORCE_COLOR","hasForceColor","forceColorValue","forceColorValueIsString","forceColor","minColorLevel","osRelease","sign","version","isTTY","isStdoutColorSupported","isStderrColorSupported"],"mappings":"6DAWA,IAAMA,EAA2BC,GAA8C,CAE3E,IAAMC,EAAQ,WAERC,EAASD,EAAM,MAAQ,KAEvBE,EAA4BF,EAAM,SAAWA,EAAM,MAAQ,CAAC,EAE5DG,EAAkBD,EAAK,MAAQA,EAAK,MAAQ,CAAC,EAQ7CE,EAAcC,GAA2B,CAC3C,IAAMC,EAAqBH,EAAK,QAAQ,IAAI,EAEtCI,EAAWJ,EAAK,UAAWK,GAASH,EAAM,KAAKG,CAAI,CAAC,EAE1D,OAAOD,IAAa,KAAOD,IAAuB,IAAMC,EAAWD,EACvE,EAEIG,EAAkD,CAAC,EAEvD,GAAI,CAGAA,EAAcR,EAASC,EAAK,IAAI,SAAS,EAAIA,EAAK,KAAO,CAAC,CAC9D,MAA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AAa,YAAa,QAAS,WAAW,EAAE,KAAMQ,GAASA,KAAQR,CAAW,GACrHA,EAAY,UAAY,WAEjB,EAGJM,EAIX,GAAIN,EAAY,mBAAmB,SAAS,UAAU,EAClD,MAAO,GAGX,GAAI,qBAAsBA,EAGtB,MAAO,gCAAgC,KAAKA,EAAY,gBAA0B,EAAI,EAAkB,EAG5G,GAAIA,EAAY,YAAc,YAC1B,MAAO,GAIX,GAAIA,EAAY,OAAS,cACrB,MAAO,GAGX,GAAI,iBAAkBA,EAAa,CAE/B,IAAMS,EAAU,OAAO,UAAWT,EAAY,sBAAmC,IAAI,MAAM,GAAG,EAAE,CAAC,EAAa,EAAE,EAEhH,GAAIA,EAAY,eAAiB,YAC7B,OAAOS,GAAW,EAAI,EAAoB,EAG9C,GAAIT,EAAY,eAAiB,iBAC7B,MAAO,EAEf,CAGA,GAAI,iBAAiB,KAAaA,EAAY,IAAI,EAC9C,MAAO,GAGX,IAAIU,EAAQ,GAkBZ,OAhBIlB,EACIF,IAAY,MAEZoB,EAAQnB,EAAM,KAAK,OAAO,WAAW,EAE9BD,IAAY,QAEnBoB,EAAQnB,EAAM,KAAK,OAAO,WAAW,GAElC,aAAcS,GAAe,UAAWA,EAE/CU,EAAQ,GAERA,EAAQjB,EAAK,MAAQH,CAAO,GAAK,UAAWG,EAAK,MAAQH,CAAO,EAGhEoB,GAAS,0EAA0E,KAAaV,EAAY,IAAI,EACzG,EAGP,cAAeA,EACR,EAGJM,CACX,EAEaK,EAAyB,IAAyBtB,EAAwB,KAAK,EAE/EuB,EAAyB,IAAyBvB,EAAwB,KAAK","sourcesContent":["// Some of this code is taken from https://github.com/chalk/supports-color/blob/main/index.js\n// MIT License\n// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nimport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO, SPACE_TRUE_COLORS } from \"./color-spaces\";\nimport type { ColorSupportLevel } from \"./types\";\n\n/**\n * @param {string} stdName The standard name of the stream, either \"err\" or \"out\".\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst isColorSupportedFactory = (stdName: \"err\" | \"out\"): ColorSupportLevel => {\n // eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/no-explicit-any\n const _this = globalThis as any;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const isDeno = _this.Deno != null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access\n const proc: Record<string, any> = _this.process ?? _this.Deno ?? {};\n // Node -> `argv`, Deno -> `args`\n const argv: string[] = (proc.argv ?? proc.args ?? []) as string[];\n\n /**\n * Detect whether flags exist with `-` or `--` prefix in command-line arguments.\n *\n * @param {RegExp} regex The RegEx to match all possible flags.\n * @return {boolean}\n */\n const oneOfFlags = (regex: RegExp): boolean => {\n const terminatorPosition = argv.indexOf(\"--\");\n\n const position = argv.findIndex((flag) => regex.test(flag));\n\n return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);\n };\n\n let environment: Record<string, string | undefined> = {};\n\n try {\n // Deno requires the permission for the access to env, use the `--allow-env` flag: deno run --allow-env ./app.js\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n environment = isDeno ? proc.env.toObject() : proc.env ?? {};\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n\n const FORCE_COLOR = \"FORCE_COLOR\";\n const hasForceColor = FORCE_COLOR in environment;\n // eslint-disable-next-line security/detect-object-injection\n const forceColorValue = environment[FORCE_COLOR] ? String(environment[FORCE_COLOR]) : undefined;\n const forceColorValueIsString = Object.prototype.toString.call(forceColorValue).slice(8, -1) === \"String\";\n\n let forceColor: ColorSupportLevel | undefined;\n\n if (forceColorValue === \"true\") {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValue === \"false\") {\n forceColor = SPACE_MONO;\n } else if (forceColorValueIsString && (forceColorValue as string).length === 0) {\n forceColor = SPACE_16_COLORS;\n } else if (forceColorValueIsString && (forceColorValue as string).length > 0) {\n forceColor = Math.min(Number.parseInt(forceColorValue as string, 10), 3) as ColorSupportLevel;\n }\n\n if (forceColorValue !== \"true\" && forceColorValue !== \"false\" && forceColor !== undefined && forceColor < 4) {\n return forceColor;\n }\n\n const isForceDisabled =\n // eslint-disable-next-line regexp/no-unused-capturing-group\n \"NO_COLOR\" in environment || (hasForceColor && forceColor === 0) || oneOfFlags(/^-{1,2}(no-color|no-colors|color=false|color=never)$/);\n\n if (isForceDisabled) {\n return SPACE_MONO;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=256)$/)) {\n return SPACE_256_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (oneOfFlags(/^-{1,2}(color=16m|color=full|color=truecolor)$/)) {\n return SPACE_TRUE_COLORS;\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n const isForceEnabled = oneOfFlags(/^-{1,2}(color|colors|color=true|color=always)$/);\n\n if (isForceEnabled) {\n return SPACE_16_COLORS;\n }\n\n // note: the order of checks is important\n // many terminals that support truecolor have TERM as `xterm-256colors` but do not set COLORTERM to `truecolor`\n // therefore they can be detected by specific EVN variables\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n const minColorLevel = forceColor || SPACE_MONO;\n\n // Check for Azure DevOps pipelines.\n // Has to be above the `stream isTTY` check.\n if (\"TF_BUILD\" in environment && \"AGENT_NAME\" in environment) {\n return SPACE_16_COLORS;\n }\n\n const isDumbTerminal: boolean = (environment.TERM && /-mono|dumb/i.test(environment.TERM)) as boolean;\n\n if (isDumbTerminal) {\n return minColorLevel;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if ((isDeno ? _this.Deno.build.os : proc.platform) === \"win32\") {\n try {\n // Deno requires the permission for the access to the operating system, use the `--allow-sys` flag: deno run --allow-sys ./app.js\n\n // Windows 10 build 10586 is the first Windows release that supports 256 colors.\n // Windows 10 build 14931 is the first release that supports 16m/TrueColor.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n const osRelease = (isDeno ? _this.Deno.osRelease() : proc.os.release()).split(\".\");\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10_586) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return Number(osRelease[2]) >= 14_931 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n return SPACE_16_COLORS;\n } catch {\n // Deno: if interactive permission is not granted, do nothing, no colors\n }\n }\n\n if (\"CI\" in environment) {\n if (\"GITHUB_ACTIONS\" in environment || \"GITHUB_WORKFLOW\" in environment || \"GITEA_ACTIONS\" in environment) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\n [\"TRAVIS\", \"CIRCLECI\", \"APPVEYOR\", \"GITLAB_CI\", \"BUILDKITE\", \"DRONE\", \"GITLAB_CI\"].some((sign) => sign in environment) ||\n environment.CI_NAME === \"codeship\"\n ) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n }\n\n // JetBrains IDEA: JetBrains-JediTerm\n if (environment.TERMINAL_EMULATOR?.includes(\"JediTerm\")) {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TEAMCITY_VERSION\" in environment) {\n // https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingMessages\n // eslint-disable-next-line regexp/no-unused-capturing-group\n return /^(9\\.(0*[1-9]\\d*)\\.|\\d{2,}\\.)/.test(environment.TEAMCITY_VERSION as string) ? SPACE_16_COLORS : SPACE_MONO;\n }\n\n if (environment.COLORTERM === \"truecolor\") {\n return SPACE_TRUE_COLORS;\n }\n\n // kitty is GPU based terminal emulator\n if (environment.TERM === \"xterm-kitty\") {\n return SPACE_TRUE_COLORS;\n }\n\n if (\"TERM_PROGRAM\" in environment) {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const version = Number.parseInt(((environment.TERM_PROGRAM_VERSION as string) ?? \"\").split(\".\")[0] as string, 10);\n\n if (environment.TERM_PROGRAM === \"iTerm.app\") {\n return version >= 3 ? SPACE_TRUE_COLORS : SPACE_256_COLORS;\n }\n\n if (environment.TERM_PROGRAM === \"Apple_Terminal\") {\n return SPACE_256_COLORS;\n }\n }\n\n // eslint-disable-next-line regexp/no-unused-capturing-group\n if (/-256(color)?$/i.test(<string>environment.TERM)) {\n return SPACE_256_COLORS;\n }\n\n let isTTY = false;\n\n if (isDeno) {\n if (stdName === \"out\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stdout.isTerminal();\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n } else if (stdName === \"err\") {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n isTTY = _this.Deno.stderr.isTerminal();\n }\n } else if (\"PM2_HOME\" in environment && \"pm_id\" in environment) {\n // PM2 does not set process.stdout.isTTY, but colors may be supported (depends on actual terminal)\n isTTY = true;\n } else {\n isTTY = proc[\"std\" + stdName] && \"isTTY\" in proc[\"std\" + stdName];\n }\n\n if (isTTY && /^screen|^tmux|^xterm|^vt[1-5]\\d\\d|^ansi|color|mintty|rxvt|cygwin|linux/i.test(<string>environment.TERM)) {\n return SPACE_16_COLORS;\n }\n\n if (\"COLORTERM\" in environment) {\n return SPACE_16_COLORS;\n }\n\n return minColorLevel;\n};\n\nexport const isStdoutColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"out\");\n\nexport const isStderrColorSupported = (): ColorSupportLevel => isColorSupportedFactory(\"err\");\n// eslint-disable-next-line import/no-unused-modules\nexport { SPACE_16_COLORS, SPACE_256_COLORS, SPACE_MONO, SPACE_TRUE_COLORS } from \"./color-spaces\";\n// eslint-disable-next-line import/no-unused-modules\nexport type { ColorSupportLevel } from \"./types\";\n"]}
|