Skip to content

Commit b8015ef

Browse files
committed
Updates the color logic
1 parent f09e43c commit b8015ef

File tree

18 files changed

+110
-98
lines changed

18 files changed

+110
-98
lines changed

src/executeCommandLine/executeCommandLine.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ namespace ts {
9090
}
9191

9292
function createColors(sys: System) {
93-
// https://no-color.org
94-
const supportsRicherColors = sys.getEnvironmentVariable("COLORTERM") === "truecolor" || sys.getEnvironmentVariable("TERM") === "xterm-256color";
95-
96-
const showColors = defaultIsPretty(sys);
93+
const showColors = defaultIsPretty(sys) || !!sys.getEnvironmentVariable("NO_COLOR");
9794
if (!showColors) {
9895
return {
9996
bold: (str: string) => str,
@@ -103,15 +100,30 @@ namespace ts {
103100
};
104101
}
105102

103+
// There are ~3 types of terminal color support: 16 colors, 256 and 16m colors
104+
// If there is richer color support, e.g. 256+ we can use extended ANSI codes which are not just generic 'blue'
105+
// but a 'lighter blue' which is closer to the blue in the TS logo.
106+
const supportsRicherColors = sys.getEnvironmentVariable("COLORTERM") === "truecolor" || sys.getEnvironmentVariable("TERM") === "xterm-256color";
107+
106108
function bold(str: string) {
107109
return `\x1b[1m${str}\x1b[22m`;
108110
}
109111
function blue(str: string) {
110112
if (supportsRicherColors) {
113+
// https://jonasjacek.github.io/colors/ - SteelBlue3 ANSI 68
111114
return `\x1B[38;5;68m${str}\x1B[39;49m`;
112115
}
113116
else {
114-
return `\x1b[94m${str}\x1b[39m`;
117+
// This should probably only hit both Console and Powershell on Windows, as anything more modern supports more colors.
118+
// Those two colorthemes treat 'blue' as navy blue against a black background.
119+
// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
120+
const useThemeBlue = sys.getEnvironmentVariable("OS") && stringContains(sys.getEnvironmentVariable("OS").toLowerCase(), "windows");
121+
if (useThemeBlue) {
122+
return `\x1b[44m${str}\x1b[39m`;
123+
}
124+
else {
125+
return `\x1b[94m${str}\x1b[39m`;
126+
}
115127
}
116128
}
117129
function blueBackground(str: string) {

tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
5050
// "outDir": "./", /* Specify an output folder for all emitted files. */
5151
// "removeComments": true, /* Disable emitting comments. */
52-
// "noEmit": true, /* Disable emitting file from a compilation. */
52+
// "noEmit": true, /* Disable emitting files from a compilation. */
5353
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
5454
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
5555
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */

tests/baselines/reference/tsc/runWithoutArgs/initial-build/show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-can't-provide-terminal-width.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,134 +11,134 @@ tsc: The TypeScript Compiler - Version FakeTSVersion
1111

1212
COMMON COMMANDS
1313

14-
[34mtsc[39m
14+
[94mtsc[39m
1515
Compiles the current project (tsconfig.json in the working directory.)
1616

17-
[34mtsc app.ts util.ts[39m
18-
Ignoring tsconfig.json, compiles the specified files with default compiler options
17+
[94mtsc app.ts util.ts[39m
18+
Ignoring tsconfig.json, compiles the specified files with default compiler options.
1919

20-
[34mtsc -b[39m
20+
[94mtsc -b[39m
2121
Build a composite project in the working directory.
2222

23-
[34mtsc --init[39m
23+
[94mtsc --init[39m
2424
Creates a tsconfig.json with the recommended settings in the working directory.
2525

26-
[34mtsc -p .path/to/tsconfig.json[39m
27-
Compiles the TypeScript project located at the specified path
26+
[94mtsc -p ./path/to/tsconfig.json[39m
27+
Compiles the TypeScript project located at the specified path.
2828

29-
[34mtsc --help --all[39m
29+
[94mtsc --help --all[39m
3030
An expanded version of this information, showing all possible compiler options
3131

32-
[34mtsc --noEmit[39m
33-
[34mtsc --target esnext[39m
34-
Compiles the current project, with additional settings
32+
[94mtsc --noEmit[39m
33+
[94mtsc --target esnext[39m
34+
Compiles the current project, with additional settings.
3535

3636
COMMAND LINE FLAGS
3737

38-
[34m--help, -h[39m
38+
[94m--help, -h[39m
3939
Print this message.
4040

41-
[34m--watch, -w[39m
41+
[94m--watch, -w[39m
4242
Watch input files.
4343

44-
[34m--all[39m
44+
[94m--all[39m
4545
Show all compiler options.
4646

47-
[34m--version, -v[39m
47+
[94m--version, -v[39m
4848
Print the compiler's version.
4949

50-
[34m--init[39m
50+
[94m--init[39m
5151
Initializes a TypeScript project and creates a tsconfig.json file.
5252

53-
[34m--project, -p[39m
53+
[94m--project, -p[39m
5454
Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.
5555

56-
[34m--build, -b[39m
56+
[94m--build, -b[39m
5757
Build one or more projects and their dependencies, if out of date
5858

59-
[34m--showConfig[39m
59+
[94m--showConfig[39m
6060
Print the final configuration instead of building.
6161

6262
COMMON COMPILER OPTIONS
6363

64-
[34m--pretty[39m
65-
Enable color and formatting in output to make compiler errors easier to read
64+
[94m--pretty[39m
65+
Enable color and formatting in the output to make compiler errors easier to read
6666
type: boolean
6767
default: true
6868

69-
[34m--target, -t[39m
69+
[94m--target, -t[39m
7070
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
7171
one of: es3, es5, es6, es2015, es2016, es2017, es2018, es2019, es2020, es2021, esnext
7272
default: ES3
7373

74-
[34m--module, -m[39m
74+
[94m--module, -m[39m
7575
Specify what module code is generated.
7676
one of: none, commonjs, amd, system, umd, es6, es2015, es2020, esnext
7777

78-
[34m--lib[39m
78+
[94m--lib[39m
7979
Specify a set of bundled library declaration files that describe the target runtime environment.
8080
one or more: es5, es6, es2015, es7, es2016, es2017, es2018, es2019, es2020, es2021, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol, es2020.bigint, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2021.promise, es2021.string, es2021.weakref, esnext.array, esnext.symbol, esnext.asynciterable, esnext.intl, esnext.bigint, esnext.string, esnext.promise, esnext.weakref
8181

82-
[34m--allowJs[39m
82+
[94m--allowJs[39m
8383
Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files.
8484
type: boolean
8585
default: false
8686

87-
[34m--checkJs[39m
87+
[94m--checkJs[39m
8888
Enable error reporting in type-checked JavaScript files.
8989
type: boolean
9090
default: false
9191

92-
[34m--jsx[39m
92+
[94m--jsx[39m
9393
Specify what JSX code is generated.
9494
one of: preserve, react-native, react, react-jsx, react-jsxdev
9595
default: undefined
9696

97-
[34m--declaration, -d[39m
97+
[94m--declaration, -d[39m
9898
Generate .d.ts files from TypeScript and JavaScript files in your project.
9999
type: boolean
100100
default: `false`, unless `composite` is set
101101

102-
[34m--declarationMap[39m
102+
[94m--declarationMap[39m
103103
Create sourcemaps for d.ts files.
104104
type: boolean
105105
default: false
106106

107-
[34m--emitDeclarationOnly[39m
107+
[94m--emitDeclarationOnly[39m
108108
Only output d.ts files and not JavaScript files.
109109
type: boolean
110110
default: false
111111

112-
[34m--sourceMap[39m
112+
[94m--sourceMap[39m
113113
Create source map files for emitted JavaScript files.
114114
type: boolean
115115
default: false
116116

117-
[34m--outFile[39m
117+
[94m--outFile[39m
118118
Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output.
119119

120-
[34m--outDir[39m
120+
[94m--outDir[39m
121121
Specify an output folder for all emitted files.
122122

123-
[34m--removeComments[39m
123+
[94m--removeComments[39m
124124
Disable emitting comments.
125125
type: boolean
126126
default: false
127127

128-
[34m--noEmit[39m
129-
Disable emitting file from a compilation.
128+
[94m--noEmit[39m
129+
Disable emitting files from a compilation.
130130
type: boolean
131131
default: false
132132

133-
[34m--strict[39m
133+
[94m--strict[39m
134134
Enable all strict type-checking options.
135135
type: boolean
136136
default: false
137137

138-
[34m--types[39m
138+
[94m--types[39m
139139
Specify type package names to be included without being referenced in a source file.
140140

141-
[34m--esModuleInterop[39m
141+
[94m--esModuleInterop[39m
142142
Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility.
143143
type: boolean
144144
default: false

0 commit comments

Comments
 (0)