fix: use styleText instead of Bun.color

This commit is contained in:
2026-03-27 22:46:24 +07:00 Unverified
parent 6a86034fc6
commit 4521bf3078
+20 -20
View File
@@ -1,38 +1,38 @@
import { feature } from "bun:bundle";
import { color, inspect } from "bun";
import { inspect } from "bun";
import { styleText } from "node:util";
const colors = [
"deepskyblue",
"mediumspringgreen",
"pink",
"lightgreen",
"lightyellow",
"lightblue",
"lightpink",
"lightcyan",
"peachpuff",
"violet",
"lightskyblue",
"lightpink",
"red",
"green",
"yellow",
"springgreen",
"blue",
"magenta",
"cyan",
"white",
"redBright",
"greenBright",
"yellowBright",
"blueBright",
"magentaBright",
"cyanBright",
"whiteBright"
];
var i = 0;
if (!feature("API"))
console.log(
colors
.map((c, i) => `${color(c, "ansi")}${(i + 10).toString(36)}`)
.join("") + color("lightgray", "ansi"),
.map((c, i) => styleText(c, (i + 10).toString(36)))
.join(""),
);
export function createLogger(label?: string) {
const start = Date.now();
const col = color(colors[i], "ansi");
const reset = color("lightgray", "ansi");
const col = colors[i];
i = (i + 1) % colors.length;
return function log(strings: TemplateStringsArray, ...values: unknown[]) {
const normalized = `${col}${(label ?? `${Date.now() - start}ms`).padStart(7)} | ${strings
const normalized = styleText(col, `${(label ?? `${Date.now() - start}ms`).padStart(7)} | ${strings
.reduce(
(out, str, i) =>
out +
@@ -46,7 +46,7 @@ export function createLogger(label?: string) {
)
.split("\n")
.map((l, i) => (i ? `${" ".repeat(7)} | ${l}` : l))
.join("\n")}${reset}\n`;
.join("\n")}\n`);
console.write(normalized);
};
}