mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
api/console-text: refactor
This commit is contained in:
parent
b22d0efbf1
commit
5ea23bee13
1 changed files with 25 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue