Skip to content

Commit 8b15b92

Browse files
authored
Support hex prefix colors with modifiers (#450)
1 parent 7631bec commit 8b15b92

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

docs/cli/prefixing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ $ concurrently -c red,blue 'echo Hello there' 'echo General Kenobi!'
8282
Colors can take modifiers too. Several can be applied at once by prepending `.<modifier 1>.<modifier 2>` and so on.
8383

8484
```bash
85-
$ concurrently -c red,bold.blue.dim 'echo Hello there' 'echo General Kenobi!'
85+
$ concurrently -c '#23de43.inverse,bold.blue.dim' 'echo Hello there' 'echo General Kenobi!'
8686
```
8787

8888
<details>

src/logger.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,21 @@ describe('#logCommandText()', () => {
232232
expect(logger.log).toHaveBeenCalledWith(chalk.hex(prefixColor)('[1]') + ' ', 'foo', cmd);
233233
});
234234

235+
it('logs prefix using prefixColor from command if prefixColor is a hex value with modifiers', () => {
236+
const { logger } = createLogger({});
237+
const prefixColor = '#32bd8a.inverse';
238+
const cmd = new FakeCommand('', undefined, 1, {
239+
prefixColor,
240+
});
241+
logger.logCommandText('foo', cmd);
242+
243+
expect(logger.log).toHaveBeenCalledWith(
244+
chalk.hex(prefixColor).inverse('[1]') + ' ',
245+
'foo',
246+
cmd,
247+
);
248+
});
249+
235250
it('does nothing if command is hidden by name', () => {
236251
const { logger } = createLogger({ hide: ['abc'] });
237252
const cmd = new FakeCommand('abc');

src/logger.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ export class Logger {
156156
colorText(command: Command, text: string) {
157157
let color: chalk.Chalk;
158158
if (command.prefixColor?.startsWith('#')) {
159-
color = this.chalk.hex(command.prefixColor);
159+
const [hexColor, ...modifiers] = command.prefixColor.split('.');
160+
color = this.chalk.hex(hexColor);
161+
const modifiedColor = getChalkPath(color, modifiers.join('.'));
162+
if (modifiedColor) {
163+
color = modifiedColor;
164+
}
160165
} else {
161166
const defaultColor = getChalkPath(this.chalk, defaults.prefixColors) as Chalk;
162167
color = getChalkPath(this.chalk, command.prefixColor ?? '') ?? defaultColor;

0 commit comments

Comments
 (0)