From 5ea23bee134de366a8e7ebb99b6413505c4a8128 Mon Sep 17 00:00:00 2001 From: jj Date: Sun, 27 Oct 2024 17:52:04 +0000 Subject: [PATCH] api/console-text: refactor --- api/src/misc/console-text.js | 37 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/api/src/misc/console-text.js b/api/src/misc/console-text.js index 6ce747d7..8df8fcc6 100644 --- a/api/src/misc/console-text.js +++ b/api/src/misc/console-text.js @@ -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"; + } + + return ANSI[color.toUpperCase()] + text + ANSI.RESET; } -export function Red(tt) { - return t("\x1b[31m", tt) +export function Bright(text) { + return wrap('bright', text); } -export function Green(tt) { - return t("\x1b[32m", tt) +export function Red(text) { + return wrap('red', text); } -export function Cyan(tt) { - return t("\x1b[36m", tt) +export function Green(text) { + return wrap('green', text); } -export function Yellow(tt) { - return t("\x1b[93m", tt) +export function Cyan(text) { + return wrap('cyan', text); +} + +export function Yellow(text) { + return wrap('yellow', text); }