api/console-text: refactor

This commit is contained in:
jj 2024-10-27 17:52:04 +00:00
parent b22d0efbf1
commit 5ea23bee13
No known key found for this signature in database

View file

@ -1,23 +1,36 @@
function t(color, tt) { const ANSI = {
return color + tt + "\x1b[0m" RESET: "\x1b[0m",
BRIGHT: "\x1b[1m",
RED: "\x1b[31m",
GREEN: "\x1b[32m",
CYAN: "\x1b[36m",
YELLOW: "\x1b[93m"
} }
export function Bright(tt) { function wrap(color, text) {
return t("\x1b[1m", tt) if (!ANSI[color.toUpperCase()]) {
throw "invalid color";
} }
export function Red(tt) { return ANSI[color.toUpperCase()] + text + ANSI.RESET;
return t("\x1b[31m", tt)
} }
export function Green(tt) { export function Bright(text) {
return t("\x1b[32m", tt) return wrap('bright', text);
} }
export function Cyan(tt) { export function Red(text) {
return t("\x1b[36m", tt) return wrap('red', text);
} }
export function Yellow(tt) { export function Green(text) {
return t("\x1b[93m", tt) return wrap('green', text);
}
export function Cyan(text) {
return wrap('cyan', text);
}
export function Yellow(text) {
return wrap('yellow', text);
} }