-
Notifications
You must be signed in to change notification settings - Fork 0
/
colortest.go
56 lines (43 loc) · 1.01 KB
/
colortest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"io"
"os"
"github.com/shiena/ansicolor"
)
const rune = " ••• "
func main() {
w := ansicolor.NewAnsiColorWriter(os.Stdout)
fmt.Println()
fmt.Fprint(w, " ")
for bg := 40; bg <= 47; bg++ {
fmt.Fprintf(w, " %dm ", bg)
}
fmt.Fprintln(w)
for row := 30; row <= 37; row++ {
control := fmt.Sprintf("%vm", row)
bold := fmt.Sprintf("1;%v", row)
controlBold := fmt.Sprintf("%vm", bold)
printLine(w, row, control, false)
printLine(w, row, controlBold, true)
}
fmt.Println()
}
func printLine(w io.Writer, fg int, control string, bold bool) {
fmt.Fprintf(w, "%+6s ", control)
// No BG color
cmd := fmt.Sprintf("\x1b[%dm %v ", fg, rune)
if bold {
cmd = fmt.Sprintf("\x1b[1;%dm %v ", fg, rune)
}
fmt.Fprint(w, cmd)
for bg := 40; bg <= 47; bg++ {
cmd := fmt.Sprintf("\x1b[%d;%dm %v ", fg, bg, rune)
if bold {
cmd = fmt.Sprintf("\x1b[1;%d;%dm %v ", fg, bg, rune)
}
fmt.Fprint(w, cmd)
fmt.Fprint(w, "\x1b[0m ")
}
fmt.Fprintln(w)
}