Skip to content

Commit

Permalink
Support for hex colors in prefixColor (#261)
Browse files Browse the repository at this point in the history
Closes #260
  • Loading branch information
Ramakrishna committed Feb 20, 2021
1 parent 2e1ad01 commit 6fcbf19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
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
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
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
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

0 comments on commit 6fcbf19

Please sign in to comment.