From dc915f2e1f2601f26a0632c559d98ddd64d0fc16 Mon Sep 17 00:00:00 2001 From: Garret MH Date: Fri, 3 Nov 2023 09:32:33 -0700 Subject: [PATCH 1/3] Support hex prefix colors with modifiers --- src/logger.spec.ts | 11 +++++++++++ src/logger.ts | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/logger.spec.ts b/src/logger.spec.ts index caee89dc..5968cafc 100644 --- a/src/logger.spec.ts +++ b/src/logger.spec.ts @@ -197,6 +197,17 @@ 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..7326629e 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); From 5891b65530f5fa68e0e5f820598517d1bc28122e Mon Sep 17 00:00:00 2001 From: Garret MH Date: Tue, 12 Dec 2023 18:30:53 -0800 Subject: [PATCH 2/3] Run lint & format --- src/logger.spec.ts | 6 +++++- src/logger.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/logger.spec.ts b/src/logger.spec.ts index 5968cafc..d4b8b08a 100644 --- a/src/logger.spec.ts +++ b/src/logger.spec.ts @@ -205,7 +205,11 @@ describe('#logCommandText()', () => { }); logger.logCommandText('foo', cmd); - expect(logger.log).toHaveBeenCalledWith(chalk.hex(prefixColor).inverse()('[1]') + ' ', 'foo', cmd); + expect(logger.log).toHaveBeenCalledWith( + chalk.hex(prefixColor).inverse()('[1]') + ' ', + 'foo', + cmd, + ); }); it('does nothing if command is hidden by name', () => { diff --git a/src/logger.ts b/src/logger.ts index 7326629e..6acec2a9 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -121,10 +121,10 @@ export class Logger { colorText(command: Command, text: string) { let color: chalk.Chalk; if (command.prefixColor && command.prefixColor.startsWith('#')) { - const [hexColor, ...modifiers] = command.prefixColor.split('.') + const [hexColor, ...modifiers] = command.prefixColor.split('.'); color = chalk.hex(hexColor); if (modifiers.length) { - color = _.get(color, modifiers) + color = _.get(color, modifiers); } } else { const defaultColor = _.get(chalk, defaults.prefixColors, chalk.reset); From fe15928802793b42b54e4603ab9949afa9b0dc3c Mon Sep 17 00:00:00 2001 From: Garret MH Date: Tue, 12 Dec 2023 18:32:41 -0800 Subject: [PATCH 3/3] Fix test typo --- src/logger.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logger.spec.ts b/src/logger.spec.ts index d4b8b08a..aa60e445 100644 --- a/src/logger.spec.ts +++ b/src/logger.spec.ts @@ -206,7 +206,7 @@ describe('#logCommandText()', () => { logger.logCommandText('foo', cmd); expect(logger.log).toHaveBeenCalledWith( - chalk.hex(prefixColor).inverse()('[1]') + ' ', + chalk.hex(prefixColor).inverse('[1]') + ' ', 'foo', cmd, );