2014-12-13 08:14:18 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-12-13 13:38:52 +01:00
|
|
|
"fmt"
|
2014-12-13 11:01:37 +01:00
|
|
|
"strings"
|
2014-12-13 08:14:18 +01:00
|
|
|
"math/rand"
|
2014-12-13 23:42:43 +01:00
|
|
|
"time"
|
2014-12-13 08:14:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const RESET string = "\033[0m"
|
|
|
|
const BOLD string = "\033[1m"
|
|
|
|
const DIM string = "\033[2m"
|
2014-12-13 11:01:37 +01:00
|
|
|
const ITALIC string = "\033[3m"
|
2014-12-13 08:14:18 +01:00
|
|
|
const UNDERLINE string = "\033[4m"
|
|
|
|
const BLINK string = "\033[5m"
|
|
|
|
const INVERT string = "\033[7m"
|
|
|
|
|
|
|
|
var colors = []string { "31", "32", "33", "34", "35", "36", "37", "91", "92", "93", "94", "95", "96", "97" }
|
|
|
|
|
2014-12-13 13:38:52 +01:00
|
|
|
func RandomColor256() string {
|
|
|
|
return fmt.Sprintf("38;05;%d", rand.Intn(256))
|
|
|
|
}
|
|
|
|
|
2014-12-13 08:14:18 +01:00
|
|
|
func RandomColor() string {
|
|
|
|
return colors[rand.Intn(len(colors))]
|
|
|
|
}
|
|
|
|
|
2014-12-13 11:01:37 +01:00
|
|
|
func ColorString(color string, msg string) string {
|
|
|
|
return BOLD + "\033[" + color + "m" + msg + RESET
|
|
|
|
}
|
|
|
|
|
2014-12-13 23:42:43 +01:00
|
|
|
func RandomColorInit() {
|
|
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
}
|
|
|
|
|
2014-12-13 11:01:37 +01:00
|
|
|
// Horrible hack to "continue" the previous string color and format
|
|
|
|
// after a RESET has been encountered.
|
|
|
|
// This is not HTML where you can just do a </style> to resume your previous formatting!
|
|
|
|
func ContinuousFormat(format string, str string) string {
|
|
|
|
return SYSTEM_MESSAGE_FORMAT + strings.Replace(str, RESET, format, -1) + RESET
|
2014-12-13 08:14:18 +01:00
|
|
|
}
|