| 1 |
package jl |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
) |
| 6 |
|
| 7 |
type Color int |
| 8 |
|
| 9 |
|
| 10 |
const ( |
| 11 |
Black Color = iota + 30 |
| 12 |
Red |
| 13 |
Green |
| 14 |
Yellow |
| 15 |
Blue |
| 16 |
Magenta |
| 17 |
Cyan |
| 18 |
White |
| 19 |
) |
| 20 |
|
| 21 |
|
| 22 |
const ( |
| 23 |
HiBlack Color = iota + 90 |
| 24 |
HiRed |
| 25 |
HiGreen |
| 26 |
HiYellow |
| 27 |
HiBlue |
| 28 |
HiMagenta |
| 29 |
HiCyan |
| 30 |
HiWhite |
| 31 |
) |
| 32 |
|
| 33 |
|
| 34 |
var AllColors = []Color{ |
| 35 |
|
| 36 |
|
| 37 |
Green, |
| 38 |
Yellow, |
| 39 |
Blue, |
| 40 |
Magenta, |
| 41 |
Cyan, |
| 42 |
White, |
| 43 |
HiBlack, |
| 44 |
HiRed, |
| 45 |
HiGreen, |
| 46 |
HiYellow, |
| 47 |
HiBlue, |
| 48 |
HiMagenta, |
| 49 |
HiCyan, |
| 50 |
HiWhite, |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
func ColorText(c Color, text string) string { |
| 55 |
return fmt.Sprintf("\x1b[%dm%s\x1b[0m", c, text) |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
var LevelColors = map[string]Color{ |
| 60 |
"trace": White, |
| 61 |
"debug": White, |
| 62 |
"info": Green, |
| 63 |
"warn": Yellow, |
| 64 |
"warning": Yellow, |
| 65 |
"error": Red, |
| 66 |
"fatal": Red, |
| 67 |
"panic": Red, |
| 68 |
} |