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

Support for hex colors in prefixColor #260 #261

Merged
merged 2 commits into from
Feb 20, 2021
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ Prefix styling
- Available modifiers: reset, bold, dim, italic,
underline, inverse, hidden, strikethrough
- Available colors: black, red, green, yellow, blue,
magenta, cyan, white, gray
magenta, cyan, white, gray, or any hex values for
colors, eg #23de43
- Available background colors: bgBlack, bgRed,
bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite
See https://www.npmjs.com/package/chalk for more
Expand Down
3 changes: 2 additions & 1 deletion bin/concurrently.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ const args = yargs
'Comma-separated list of chalk colors to use on prefixes. ' +
'If there are more commands than colors, the last color will be repeated.\n' +
'- Available modifiers: reset, bold, dim, italic, underline, inverse, hidden, strikethrough\n' +
'- Available colors: black, red, green, yellow, blue, magenta, cyan, white, gray\n' +
'- Available colors: black, red, green, yellow, blue, magenta, cyan, white, gray \n' +
'or any hex values for colors, eg #23de43\n' +
'- Available background colors: bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite\n' +
'See https://www.npmjs.com/package/chalk for more information.',
default: defaults.prefixColors,
Expand Down
7 changes: 6 additions & 1 deletion src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ module.exports = class Logger {
}

colorText(command, text) {
const color = _.get(chalk, command.prefixColor, chalk.gray.dim);
let color;
if (command.prefixColor && command.prefixColor.startsWith('#')) {
color = chalk.hex(command.prefixColor);
} else {
color = _.get(chalk, command.prefixColor, chalk.gray.dim);
}
return color(text);
}

Expand Down
8 changes: 8 additions & 0 deletions src/logger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ describe('#logCommandText()', () => {

expect(logger.log).toHaveBeenCalledWith(chalk.gray.dim('[1]') + ' ', 'foo');
});

it('logs prefix using prefixColor from command if prefixColor is a hex value', () => {
const logger = createLogger();
const prefixColor = '#32bd8a';
logger.logCommandText('foo', {prefixColor, index: 1});

expect(logger.log).toHaveBeenCalledWith(chalk.hex(prefixColor)('[1]') + ' ', 'foo');
});
});

describe('#logCommandEvent()', () => {
Expand Down