77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
|
package generator
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
type Color int
|
||
|
|
||
|
const (
|
||
|
GREY Color = 30 + iota
|
||
|
RED
|
||
|
GREEN
|
||
|
YELLOW
|
||
|
BLUE
|
||
|
MAGENTA
|
||
|
CYAN
|
||
|
)
|
||
|
|
||
|
var waiter = sync.Mutex{}
|
||
|
|
||
|
func color(c Color, args ...interface{}) {
|
||
|
waiter.Lock()
|
||
|
fmt.Fprintf(os.Stdout, "\x1b[%dm", c)
|
||
|
fmt.Fprint(os.Stdout, args...)
|
||
|
fmt.Fprintf(os.Stdout, "\x1b[0m\n")
|
||
|
waiter.Unlock()
|
||
|
}
|
||
|
|
||
|
func colorf(c Color, format string, args ...interface{}) {
|
||
|
waiter.Lock()
|
||
|
fmt.Fprintf(os.Stdout, "\x1b[%dm", c)
|
||
|
fmt.Fprintf(os.Stdout, format, args...)
|
||
|
fmt.Fprintf(os.Stdout, "\x1b[0m")
|
||
|
waiter.Unlock()
|
||
|
}
|
||
|
|
||
|
func Grey(args ...interface{}) {
|
||
|
color(GREY, args...)
|
||
|
}
|
||
|
|
||
|
func Red(args ...interface{}) {
|
||
|
color(RED, args...)
|
||
|
}
|
||
|
func Green(args ...interface{}) {
|
||
|
color(GREEN, args...)
|
||
|
}
|
||
|
func Yellow(args ...interface{}) {
|
||
|
color(YELLOW, args...)
|
||
|
}
|
||
|
func Blue(args ...interface{}) {
|
||
|
color(BLUE, args...)
|
||
|
}
|
||
|
func Magenta(args ...interface{}) {
|
||
|
color(MAGENTA, args...)
|
||
|
}
|
||
|
func Greyf(format string, args ...interface{}) {
|
||
|
colorf(GREY, format, args...)
|
||
|
}
|
||
|
|
||
|
func Redf(format string, args ...interface{}) {
|
||
|
colorf(RED, format, args...)
|
||
|
}
|
||
|
func Greenf(format string, args ...interface{}) {
|
||
|
colorf(GREEN, format, args...)
|
||
|
}
|
||
|
func Yellowf(format string, args ...interface{}) {
|
||
|
colorf(YELLOW, format, args...)
|
||
|
}
|
||
|
func Bluef(format string, args ...interface{}) {
|
||
|
colorf(BLUE, format, args...)
|
||
|
}
|
||
|
func Magentaf(format string, args ...interface{}) {
|
||
|
colorf(MAGENTA, format, args...)
|
||
|
}
|