diff --git a/src/logger.spec.ts b/src/logger.spec.ts index caee89dc..aa60e445 100644 --- a/src/logger.spec.ts +++ b/src/logger.spec.ts @@ -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'); diff --git a/src/logger.ts b/src/logger.ts index bc3f7d6d..6acec2a9 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -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);