Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Reuse log prefix colors if we run out
Thomas Scholtes committed 2 years ago
commit b979862b08d27e091545724095c3f4c027a2a91d
parent c568757675ea479abc6e0c7fe4c2065c6bc5eedd
1 file changed +4 -5
modified tests/support/logPrefix.ts
@@ -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;
  }