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 1 commit
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
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