Skip to content

Stabilize colors #1524

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

Merged
merged 4 commits into from
Sep 24, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions test/helper/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* This module is maintained to promote separation between the tests and the
* implementation.
*/
'use strict';

const ansiStyles = require('ansi-styles');

function make(name) {
const style = ansiStyles[name];
return function (string) {
return style.open + string + style.close;
};
}
const bold = make('bold');
const white = make('white');
const gray = make('gray');

// The following color definitions are contextual so that they produce expected
// values which mimic the behavior of the Chalk library.
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm');
const openDim = isSimpleWindowsTerm ? '' : ansiStyles.dim.open;
const openBlue = isSimpleWindowsTerm ? '\u001B[94m' : ansiStyles.blue.open;
// "Use `bold` by default on Windows"
// https://github.com/chalk/chalk/issues/36
const blue = string => openBlue + string + ansiStyles.blue.close;
// "(Windows) chalk.gray.dim not visible"
// https://github.com/chalk/chalk/issues/58
const dimGray = string => gray(openDim + string + ansiStyles.dim.close);

module.exports = {
blue,
boldWhite: string => bold(white(string)),
dimGray,
gray,
green: make('green'),
magenta: make('magenta'),
red: make('red'),
yellow: make('yellow')
};
Loading