fix: use styleText instead of Bun.color
This commit is contained in:
+20
-20
@@ -1,38 +1,38 @@
|
|||||||
import { feature } from "bun:bundle";
|
import { feature } from "bun:bundle";
|
||||||
import { color, inspect } from "bun";
|
import { inspect } from "bun";
|
||||||
|
import { styleText } from "node:util";
|
||||||
|
|
||||||
const colors = [
|
const colors = [
|
||||||
"deepskyblue",
|
"red",
|
||||||
"mediumspringgreen",
|
"green",
|
||||||
"pink",
|
|
||||||
"lightgreen",
|
|
||||||
"lightyellow",
|
|
||||||
"lightblue",
|
|
||||||
"lightpink",
|
|
||||||
"lightcyan",
|
|
||||||
"peachpuff",
|
|
||||||
"violet",
|
|
||||||
"lightskyblue",
|
|
||||||
"lightpink",
|
|
||||||
"yellow",
|
"yellow",
|
||||||
"springgreen",
|
"blue",
|
||||||
|
"magenta",
|
||||||
|
"cyan",
|
||||||
|
"white",
|
||||||
|
"redBright",
|
||||||
|
"greenBright",
|
||||||
|
"yellowBright",
|
||||||
|
"blueBright",
|
||||||
|
"magentaBright",
|
||||||
|
"cyanBright",
|
||||||
|
"whiteBright"
|
||||||
];
|
];
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
if (!feature("API"))
|
if (!feature("API"))
|
||||||
console.log(
|
console.log(
|
||||||
colors
|
colors
|
||||||
.map((c, i) => `${color(c, "ansi")}${(i + 10).toString(36)}`)
|
.map((c, i) => styleText(c, (i + 10).toString(36)))
|
||||||
.join("") + color("lightgray", "ansi"),
|
.join(""),
|
||||||
);
|
);
|
||||||
|
|
||||||
export function createLogger(label?: string) {
|
export function createLogger(label?: string) {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const col = color(colors[i], "ansi");
|
const col = colors[i];
|
||||||
const reset = color("lightgray", "ansi");
|
|
||||||
i = (i + 1) % colors.length;
|
i = (i + 1) % colors.length;
|
||||||
return function log(strings: TemplateStringsArray, ...values: unknown[]) {
|
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(
|
.reduce(
|
||||||
(out, str, i) =>
|
(out, str, i) =>
|
||||||
out +
|
out +
|
||||||
@@ -46,7 +46,7 @@ export function createLogger(label?: string) {
|
|||||||
)
|
)
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map((l, i) => (i ? `${" ".repeat(7)} | ${l}` : l))
|
.map((l, i) => (i ? `${" ".repeat(7)} | ${l}` : l))
|
||||||
.join("\n")}${reset}\n`;
|
.join("\n")}\n`);
|
||||||
console.write(normalized);
|
console.write(normalized);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user