Skip to content

Commit

Permalink
Merge fe15928 into 0c64306
Browse files Browse the repository at this point in the history
  • Loading branch information
garretmh committed Dec 13, 2023
2 parents 0c64306 + fe15928 commit 0c385ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ describe('#logCommandText()', () => {
expect(logger.log).toHaveBeenCalledWith(chalk.hex(prefixColor)('[1]') + ' ', 'foo', cmd);
});

it('logs prefix using prefixColor from command if prefixColor is a hex value with modifiers', () => {
const { logger } = createLogger({});
const prefixColor = '#32bd8a.inverse';
const cmd = new FakeCommand('', undefined, 1, {
prefixColor,
});
logger.logCommandText('foo', cmd);

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

it('does nothing if command is hidden by name', () => {
const { logger } = createLogger({ hide: ['abc'] });
const cmd = new FakeCommand('abc');
Expand Down
6 changes: 5 additions & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ export class Logger {
colorText(command: Command, text: string) {
let color: chalk.Chalk;
if (command.prefixColor && command.prefixColor.startsWith('#')) {
color = chalk.hex(command.prefixColor);
const [hexColor, ...modifiers] = command.prefixColor.split('.');
color = chalk.hex(hexColor);
if (modifiers.length) {
color = _.get(color, modifiers);
}
} else {
const defaultColor = _.get(chalk, defaults.prefixColors, chalk.reset);
color = _.get(chalk, command.prefixColor ?? '', defaultColor);
Expand Down

0 comments on commit 0c385ff

Please sign in to comment.