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 hex prefix colors with modifiers #450

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@
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);

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 16 on Ubuntu

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Check

Replace `chalk.hex(prefixColor).inverse()('[1]')·+·'·',·'foo',·cmd` with `⏎············chalk.hex(prefixColor).inverse()('[1]')·+·'·',⏎············'foo',⏎············cmd,⏎········`

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 16 on Windows

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 16 on macOS

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on Ubuntu

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on Windows

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 18 on macOS

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on Ubuntu

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on Windows

This expression is not callable.

Check failure on line 208 in src/logger.spec.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on macOS

This expression is not callable.
});

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 @@
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('.')

Check failure on line 124 in src/logger.ts

View workflow job for this annotation

GitHub Actions / Check

Insert `;`
color = chalk.hex(hexColor);
if (modifiers.length) {
color = _.get(color, modifiers)

Check failure on line 127 in src/logger.ts

View workflow job for this annotation

GitHub Actions / Check

Insert `;`
}
} else {
const defaultColor = _.get(chalk, defaults.prefixColors, chalk.reset);
color = _.get(chalk, command.prefixColor ?? '', defaultColor);
Expand Down
Loading