Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dim style workaround for Windows #331

Merged
merged 1 commit into from Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 5 additions & 21 deletions index.js
Expand Up @@ -4,8 +4,6 @@ const ansiStyles = require('ansi-styles');
const {stdout: stdoutColor} = require('supports-color');
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',
Expand Down Expand Up @@ -63,14 +61,14 @@ for (const [styleName, style] of Object.entries(ansiStyles)) {

styles[styleName] = {
get() {
return build.call(this, [...(this._styles || []), style], this._empty, styleName);
return build.call(this, [...(this._styles || []), style], this._empty);
}
};
}

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

Expand All @@ -90,7 +88,7 @@ for (const model of Object.keys(ansiStyles.color.ansi)) {
close: ansiStyles.color.close,
closeRe: ansiStyles.color.closeRe
};
return build.call(this, [...(this._styles || []), codes], this._empty, model);
return build.call(this, [...(this._styles || []), codes], this._empty);
};
}
};
Expand All @@ -113,15 +111,15 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
close: ansiStyles.bgColor.close,
closeRe: ansiStyles.bgColor.closeRe
};
return build.call(this, [...(this._styles || []), codes], this._empty, model);
return build.call(this, [...(this._styles || []), codes], this._empty);
};
}
};
}

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

function build(_styles, _empty, key) {
function build(_styles, _empty) {
const builder = (...arguments_) => applyStyle.call(builder, ...arguments_);
builder._styles = _styles;
builder._empty = _empty;
Expand All @@ -148,9 +146,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 All @@ -165,14 +160,6 @@ function applyStyle(...arguments_) {
return this._empty ? '' : string;
}

// 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 All @@ -185,9 +172,6 @@ function applyStyle(...arguments_) {
string = string.replace(/\r?\n/g, `${code.close}$&${code.open}`);
}

// Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
ansiStyles.dim.open = originalDim;

return string;
}

Expand Down
51 changes: 0 additions & 51 deletions test/windows.js

This file was deleted.