|
| 1 | +package colorstring |
| 2 | + |
| 3 | +// ANSI color escape sequences |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | +) |
| 8 | + |
| 9 | +// Color ... |
| 10 | +type Color string |
| 11 | + |
| 12 | +const ( |
| 13 | + blackColor Color = "\x1b[30;1m" |
| 14 | + redColor Color = "\x1b[31;1m" |
| 15 | + greenColor Color = "\x1b[32;1m" |
| 16 | + yellowColor Color = "\x1b[33;1m" |
| 17 | + blueColor Color = "\x1b[34;1m" |
| 18 | + magentaColor Color = "\x1b[35;1m" |
| 19 | + cyanColor Color = "\x1b[36;1m" |
| 20 | + resetColor Color = "\x1b[0m" |
| 21 | +) |
| 22 | + |
| 23 | +// ColorFunc ... |
| 24 | +type ColorFunc func(a ...interface{}) string |
| 25 | + |
| 26 | +func addColor(color Color, msg string) string { |
| 27 | + return string(color) + msg + string(resetColor) |
| 28 | +} |
| 29 | + |
| 30 | +// NoColor ... |
| 31 | +func NoColor(a ...interface{}) string { |
| 32 | + return fmt.Sprint(a...) |
| 33 | +} |
| 34 | + |
| 35 | +// Black ... |
| 36 | +func Black(a ...interface{}) string { |
| 37 | + return addColor(blackColor, fmt.Sprint(a...)) |
| 38 | +} |
| 39 | + |
| 40 | +// Red ... |
| 41 | +func Red(a ...interface{}) string { |
| 42 | + return addColor(redColor, fmt.Sprint(a...)) |
| 43 | +} |
| 44 | + |
| 45 | +// Green ... |
| 46 | +func Green(a ...interface{}) string { |
| 47 | + return addColor(greenColor, fmt.Sprint(a...)) |
| 48 | +} |
| 49 | + |
| 50 | +// Yellow ... |
| 51 | +func Yellow(a ...interface{}) string { |
| 52 | + return addColor(yellowColor, fmt.Sprint(a...)) |
| 53 | +} |
| 54 | + |
| 55 | +// Blue ... |
| 56 | +func Blue(a ...interface{}) string { |
| 57 | + return addColor(blueColor, fmt.Sprint(a...)) |
| 58 | +} |
| 59 | + |
| 60 | +// Magenta ... |
| 61 | +func Magenta(a ...interface{}) string { |
| 62 | + return addColor(magentaColor, fmt.Sprint(a...)) |
| 63 | +} |
| 64 | + |
| 65 | +// Cyan ... |
| 66 | +func Cyan(a ...interface{}) string { |
| 67 | + return addColor(cyanColor, fmt.Sprint(a...)) |
| 68 | +} |
| 69 | + |
| 70 | +// ColorfFunc ... |
| 71 | +type ColorfFunc func(format string, a ...interface{}) string |
| 72 | + |
| 73 | +// NoColorf ... |
| 74 | +func NoColorf(format string, a ...interface{}) string { |
| 75 | + return NoColor(fmt.Sprintf(format, a...)) |
| 76 | +} |
| 77 | + |
| 78 | +// Blackf ... |
| 79 | +func Blackf(format string, a ...interface{}) string { |
| 80 | + return Black(fmt.Sprintf(format, a...)) |
| 81 | +} |
| 82 | + |
| 83 | +// Redf ... |
| 84 | +func Redf(format string, a ...interface{}) string { |
| 85 | + return Red(fmt.Sprintf(format, a...)) |
| 86 | +} |
| 87 | + |
| 88 | +// Greenf ... |
| 89 | +func Greenf(format string, a ...interface{}) string { |
| 90 | + return Green(fmt.Sprintf(format, a...)) |
| 91 | +} |
| 92 | + |
| 93 | +// Yellowf ... |
| 94 | +func Yellowf(format string, a ...interface{}) string { |
| 95 | + return Yellow(fmt.Sprintf(format, a...)) |
| 96 | +} |
| 97 | + |
| 98 | +// Bluef ... |
| 99 | +func Bluef(format string, a ...interface{}) string { |
| 100 | + return Blue(fmt.Sprintf(format, a...)) |
| 101 | +} |
| 102 | + |
| 103 | +// Magentaf ... |
| 104 | +func Magentaf(format string, a ...interface{}) string { |
| 105 | + return Magenta(fmt.Sprintf(format, a...)) |
| 106 | +} |
| 107 | + |
| 108 | +// Cyanf ... |
| 109 | +func Cyanf(format string, a ...interface{}) string { |
| 110 | + return Cyan(fmt.Sprintf(format, a...)) |
| 111 | +} |
0 commit comments