internal/style.go 1.3 K raw
1
package internal
2
3
import (
4
	"fmt"
5
)
6
7
const (
8
	Reset   = "\033[0m"
9
	Bold    = "\033[1m"
10
	Red     = "\033[31m"
11
	Green   = "\033[32m"
12
	Yellow  = "\033[33m"
13
	Blue    = "\033[34m"
14
	Magenta = "\033[35m"
15
	Cyan    = "\033[36m"
16
	White   = "\033[37m"
17
	Gray    = "\033[90m"
18
)
19
20
type Color struct {
21
	Name string
22
	Code string
23
}
24
25
// Palette can be edited or expanded
26
var Palette = []Color{
27
	{"Red", Red},
28
	{"Green", Green},
29
	{"Yellow", Yellow},
30
	{"Blue", Blue},
31
	{"Magenta", Magenta},
32
	{"Cyan", Cyan},
33
	{"White", White},
34
	{"Gray", Gray},
35
}
36
37
// Customize key color and swatch symbol
38
const KeyColor = Yellow
39
const PaletteSwatch = "●"
40
41
func Colorize(color, s string) string {
42
	return color + s + Reset
43
}
44
45
func PrintPalette() {
46
	fmt.Print("  ")
47
	for _, c := range Palette {
48
		swatch := Colorize(c.Code, PaletteSwatch + "  ")
49
		fmt.Print(swatch)
50
	}
51
	fmt.Println()
52
}
53
54
func PrintRows(rows []Row) {
55
	width := labelWidth(rows)
56
57
	fmt.Println()
58
	for _, row := range rows {
59
		if row.Value == "Unknown" {
60
			continue
61
		}
62
		label := Colorize(Bold+KeyColor, fmt.Sprintf("%-*s", width, row.Key))
63
		line := "  " + label + "    " + row.Value
64
65
		fmt.Println(line)
66
	}
67
	fmt.Println()
68
}
69
70
func labelWidth(rows []Row) int {
71
	width := 0
72
	for _, row := range rows {
73
		if w := len(row.Key) + 1; w > width {
74
			width = w
75
		}
76
	}
77
	return width
78
}