Skip to content

Commit

Permalink
Remove dim style workaround for Windows (chalk#331)
Browse files Browse the repository at this point in the history
See: chalk#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.
  • Loading branch information
Methuselah96 committed Aug 29, 2021
1 parent d426f1d commit 403e4b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 69 deletions.
23 changes: 5 additions & 18 deletions index.js
Expand Up @@ -5,8 +5,6 @@ const stdoutColor = require('supports-color').stdout;

const template = require('./templates.js');

const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');

// `supportsColor.level` → `ansiStyles.color[name]` mapping
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];

Expand Down Expand Up @@ -53,14 +51,14 @@ for (const key of Object.keys(ansiStyles)) {
styles[key] = {
get() {
const codes = ansiStyles[key];
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty);
}
};
}

styles.visible = {
get() {
return build.call(this, this._styles || [], true, 'visible');
return build.call(this, this._styles || [], true);
}
};

Expand All @@ -80,7 +78,7 @@ for (const model of Object.keys(ansiStyles.color.ansi)) {
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty);
};
}
};
Expand All @@ -103,15 +101,15 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
close: ansiStyles.bgColor.close,
closeRe: ansiStyles.bgColor.closeRe
};
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty);
};
}
};
}

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

function build(_styles, _empty, key) {
function build(_styles, _empty) {
const builder = function () {
return applyStyle.apply(builder, arguments);
};
Expand Down Expand Up @@ -141,9 +139,6 @@ function build(_styles, _empty, key) {
}
});

// See below for fix regarding invisible grey/dim combination on Windows
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';

// `__proto__` is used because we must return a function, but there is
// no way to create a function with a different prototype
builder.__proto__ = proto; // eslint-disable-line no-proto
Expand Down Expand Up @@ -172,14 +167,6 @@ function applyStyle() {
return this._empty ? '' : str;
}

// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
// see https://github.com/chalk/chalk/issues/58
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
const originalDim = ansiStyles.dim.open;
if (isSimpleWindowsTerm && this.hasGrey) {
ansiStyles.dim.open = '';
}

for (const code of this._styles.slice().reverse()) {
// Replace any instances already present with a re-opening code
// otherwise only the part of the string until said closing code
Expand Down
51 changes: 0 additions & 51 deletions test/windows.js

This file was deleted.

0 comments on commit 403e4b9

Please sign in to comment.