Skip to content

Commit cd5de7a

Browse files
authored
Remove dim style workaround for Windows (#331)
See: #330 The issue seems to have been fixed in newer Windows 10 builds. We're not interested in adding a conditional for older Windows versions as the fix severely complicates the codebase, and it also creates problems for consumers as it makes the output unpredictable.
1 parent 2ca015c commit cd5de7a

2 files changed

Lines changed: 5 additions & 72 deletions

File tree

index.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const ansiStyles = require('ansi-styles');
44
const {stdout: stdoutColor} = require('supports-color');
55
const template = require('./templates.js');
66

7-
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
8-
97
// `supportsColor.level` → `ansiStyles.color[name]` mapping
108
const levelMapping = [
119
'ansi',
@@ -63,14 +61,14 @@ for (const [styleName, style] of Object.entries(ansiStyles)) {
6361

6462
styles[styleName] = {
6563
get() {
66-
return build.call(this, [...(this._styles || []), style], this._empty, styleName);
64+
return build.call(this, [...(this._styles || []), style], this._empty);
6765
}
6866
};
6967
}
7068

7169
styles.visible = {
7270
get() {
73-
return build.call(this, this._styles || [], true, 'visible');
71+
return build.call(this, this._styles || [], true);
7472
}
7573
};
7674

@@ -90,7 +88,7 @@ for (const model of Object.keys(ansiStyles.color.ansi)) {
9088
close: ansiStyles.color.close,
9189
closeRe: ansiStyles.color.closeRe
9290
};
93-
return build.call(this, [...(this._styles || []), codes], this._empty, model);
91+
return build.call(this, [...(this._styles || []), codes], this._empty);
9492
};
9593
}
9694
};
@@ -113,15 +111,15 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
113111
close: ansiStyles.bgColor.close,
114112
closeRe: ansiStyles.bgColor.closeRe
115113
};
116-
return build.call(this, [...(this._styles || []), codes], this._empty, model);
114+
return build.call(this, [...(this._styles || []), codes], this._empty);
117115
};
118116
}
119117
};
120118
}
121119

122120
const proto = Object.defineProperties(() => {}, styles);
123121

124-
function build(_styles, _empty, key) {
122+
function build(_styles, _empty) {
125123
const builder = (...arguments_) => applyStyle.call(builder, ...arguments_);
126124
builder._styles = _styles;
127125
builder._empty = _empty;
@@ -148,9 +146,6 @@ function build(_styles, _empty, key) {
148146
}
149147
});
150148

151-
// See below for fix regarding invisible grey/dim combination on Windows
152-
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';
153-
154149
// `__proto__` is used because we must return a function, but there is
155150
// no way to create a function with a different prototype
156151
builder.__proto__ = proto; // eslint-disable-line no-proto
@@ -165,14 +160,6 @@ function applyStyle(...arguments_) {
165160
return this._empty ? '' : string;
166161
}
167162

168-
// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
169-
// see https://github.com/chalk/chalk/issues/58
170-
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
171-
const originalDim = ansiStyles.dim.open;
172-
if (isSimpleWindowsTerm && this.hasGrey) {
173-
ansiStyles.dim.open = '';
174-
}
175-
176163
for (const code of this._styles.slice().reverse()) {
177164
// Replace any instances already present with a re-opening code
178165
// otherwise only the part of the string until said closing code
@@ -185,9 +172,6 @@ function applyStyle(...arguments_) {
185172
string = string.replace(/\r?\n/g, `${code.close}$&${code.open}`);
186173
}
187174

188-
// Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
189-
ansiStyles.dim.open = originalDim;
190-
191175
return string;
192176
}
193177

test/windows.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)