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