Skip to content

Commit 7e8011f

Browse files
authored
logger: enable automatic prefix colors by default (#581)
1 parent 6129083 commit 7e8011f

5 files changed

Lines changed: 26 additions & 30 deletions

File tree

docs/cli/prefixing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ $ concurrently --prefix '{index}-{pid}' 'echo Hello there' 'echo General Kenobi!
5656

5757
## Prefix Colors
5858

59-
By default, there are no colors applied to concurrently prefixes, and they just use whatever the terminal's defaults are.
59+
By default, concurrently automatically assigns colors to each command's prefix, cycling through `cyan`, `magenta`, `green`, `yellow`, and `blue` (the same palette and order used by turborepo).
6060

6161
This can be changed by using the `--prefix-colors`/`-c` flag, which takes a comma-separated list of colors to use.<br/>
62-
The available values are color names (e.g. `green`, `magenta`, `gray`, etc), a hex value (such as `#23de43`), or `auto`, to automatically select a color.
62+
The available values are color names (e.g. `green`, `magenta`, `gray`, etc), a hex value (such as `#23de43`), `auto` to automatically select a color, or `reset` to disable coloring.
6363

6464
```bash
6565
$ concurrently -c red,blue 'echo Hello there' 'echo General Kenobi!'

lib/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const prefix = '';
3535
* Default prefix color.
3636
* @see https://www.npmjs.com/package/chalk
3737
*/
38-
export const prefixColors = 'reset';
38+
export const prefixColors = 'auto';
3939

4040
/**
4141
* How many bytes we'll show on the command prefix.

lib/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export class Logger {
212212

213213
colorText(command: Command, text: string) {
214214
const prefixColor = command.prefixColor ?? '';
215-
const defaultColor = applyColor(this.chalk, defaults.prefixColors) as ChalkInstance;
215+
const defaultColor = applyColor(this.chalk, defaults.prefixColors) ?? this.chalk.reset;
216216
const color = applyColor(this.chalk, prefixColor) ?? defaultColor;
217217
return color(text);
218218
}

lib/prefix-color-selector.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,14 @@ describe('#ACCEPTABLE_CONSOLE_COLORS', () => {
180180
// always has more than one entry, which is what we enforce via this test
181181
expect(PrefixColorSelector.ACCEPTABLE_CONSOLE_COLORS.length).toBeGreaterThan(1);
182182
});
183+
184+
it('only includes colors that are visually distinct, semantically neutral, and lightweight', () => {
185+
expect(PrefixColorSelector.ACCEPTABLE_CONSOLE_COLORS).toEqual([
186+
'cyan',
187+
'magenta',
188+
'green',
189+
'yellow',
190+
'blue',
191+
]);
192+
});
183193
});

lib/prefix-color-selector.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,19 @@ export class PrefixColorSelector {
6363
this.colorGenerator = createColorGenerator(normalizedColors);
6464
}
6565

66-
/** A list of colors that are readable in a terminal. */
66+
/**
67+
* Colors used by `auto` selection and default cycling.
68+
*
69+
* Each color is chosen to be visually distinct on both dark and light
70+
* terminal backgrounds, without carrying semantic meaning (e.g. red
71+
* implies errors) or blending into default text (e.g. white/grey).
72+
* Background colors are excluded to keep output lightweight.
73+
*
74+
* This list does NOT restrict manually specified colors — any valid Chalk
75+
* color name, hex value, or modifier can be passed via `--prefix-colors`.
76+
*/
6777
public static get ACCEPTABLE_CONSOLE_COLORS() {
68-
// Colors picked randomly, can be amended if required
69-
return [
70-
// Prevent duplicates, in case the list becomes significantly large
71-
...new Set<keyof ChalkInstance>([
72-
// Text colors
73-
'cyan',
74-
'yellow',
75-
'greenBright',
76-
'blueBright',
77-
'magentaBright',
78-
'white',
79-
'grey',
80-
'red',
81-
82-
// Background colors
83-
'bgCyan',
84-
'bgYellow',
85-
'bgGreenBright',
86-
'bgBlueBright',
87-
'bgMagenta',
88-
'bgWhiteBright',
89-
'bgGrey',
90-
'bgRed',
91-
]),
92-
];
78+
return [...new Set<keyof ChalkInstance>(['cyan', 'magenta', 'green', 'yellow', 'blue'])];
9379
}
9480

9581
/**

0 commit comments

Comments
 (0)