/
main.go
96 lines (75 loc) · 1.83 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"github.com/muesli/termenv"
)
func main() {
restoreConsole, err := termenv.EnableVirtualTerminalProcessing(termenv.DefaultOutput())
if err != nil {
panic(err)
}
defer restoreConsole()
// Basic ANSI colors 0 - 15
fmt.Println(termenv.String("Basic ANSI colors").Bold())
p := termenv.ANSI
for i := int64(0); i < 16; i++ {
if i%8 == 0 {
fmt.Println()
}
// background color
bg := p.Color(fmt.Sprintf("%d", i))
c := termenv.ConvertToRGB(bg)
out := termenv.String(fmt.Sprintf(" %2d %s ", i, c.Hex()))
// apply colors
if i < 5 {
out = out.Foreground(p.Color("7"))
} else {
out = out.Foreground(p.Color("0"))
}
out = out.Background(bg)
fmt.Print(out.String()[:])
}
fmt.Printf("\n\n")
// Extended ANSI colors 16-231
fmt.Println(termenv.String("Extended ANSI colors").Bold())
p = termenv.ANSI256
for i := int64(16); i < 232; i++ {
if (i-16)%6 == 0 {
fmt.Println()
}
// background color
bg := p.Color(fmt.Sprintf("%d", i))
c := termenv.ConvertToRGB(bg)
out := termenv.String(fmt.Sprintf(" %3d %s ", i, c.Hex()))
// apply colors
if i < 28 {
out = out.Foreground(p.Color("7"))
} else {
out = out.Foreground(p.Color("0"))
}
out = out.Background(bg)
fmt.Print(out.String()[:])
}
fmt.Printf("\n\n")
// Grayscale ANSI colors 232-255
fmt.Println(termenv.String("Extended ANSI Grayscale").Bold())
p = termenv.ANSI256
for i := int64(232); i < 256; i++ {
if (i-232)%6 == 0 {
fmt.Println()
}
// background color
bg := p.Color(fmt.Sprintf("%d", i))
c := termenv.ConvertToRGB(bg)
out := termenv.String(fmt.Sprintf(" %3d %s ", i, c.Hex()))
// apply colors
if i < 244 {
out = out.Foreground(p.Color("7"))
} else {
out = out.Foreground(p.Color("0"))
}
out = out.Background(bg)
fmt.Print(out.String()[:])
}
fmt.Printf("\n\n")
}