mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-18 19:30:27 +08:00
Reuse log prefix colors if we run out
Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
This commit is contained in:
@@ -21,15 +21,14 @@ const availableColors: ColorName[] = [
|
||||
"cyan",
|
||||
];
|
||||
|
||||
let nextColorIndex = 0;
|
||||
|
||||
const assignedColors: Record<string, ColorName> = {};
|
||||
|
||||
export function logPrefix(label: string): string {
|
||||
if (assignedColors[label] === undefined) {
|
||||
const color = availableColors.pop();
|
||||
if (!color) {
|
||||
throw new Error("We're out of colors. 🤷");
|
||||
}
|
||||
|
||||
const color = availableColors[nextColorIndex];
|
||||
nextColorIndex = (nextColorIndex + 1) % availableColors.length;
|
||||
assignedColors[label] = color;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user