-
Notifications
You must be signed in to change notification settings - Fork 9
/
colors.go
103 lines (85 loc) · 3.64 KB
/
colors.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
97
98
99
100
101
102
103
// Copyright Nitric Pty Ltd.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tui
import (
"reflect"
"github.com/charmbracelet/lipgloss"
"github.com/nitrictech/cli/pkg/view/tui/components/view"
)
// ColorPalette of standard CLI UI colors
type ColorPalette struct {
White lipgloss.CompleteColor
Gray lipgloss.CompleteColor
Black lipgloss.CompleteColor
Red lipgloss.CompleteColor
Orange lipgloss.CompleteColor
Yellow lipgloss.CompleteColor
Green lipgloss.CompleteColor
Teal lipgloss.CompleteColor
Blue lipgloss.CompleteColor
Purple lipgloss.CompleteColor
}
// Colors contains our standard UI colors for CLI output
var Colors *ColorPalette = &ColorPalette{
White: lipgloss.CompleteColor{TrueColor: "#FFFFFF", ANSI256: "255", ANSI: "15"},
Gray: lipgloss.CompleteColor{TrueColor: "#696969", ANSI256: "250", ANSI: "7"},
Black: lipgloss.CompleteColor{TrueColor: "#000000", ANSI256: "16", ANSI: "0"},
Red: lipgloss.CompleteColor{TrueColor: "#E91E63", ANSI256: "197", ANSI: "1"},
Orange: lipgloss.CompleteColor{TrueColor: "#F97316", ANSI256: "208", ANSI: "3"},
Yellow: lipgloss.CompleteColor{TrueColor: "#FDE047", ANSI256: "220", ANSI: "11"},
Green: lipgloss.CompleteColor{TrueColor: "#22C55E", ANSI256: "47", ANSI: "10"},
Teal: lipgloss.CompleteColor{TrueColor: "#32D0D1", ANSI256: "51", ANSI: "14"},
Blue: lipgloss.CompleteColor{TrueColor: "#2563EB", ANSI256: "21", ANSI: "4"},
Purple: lipgloss.CompleteColor{TrueColor: "#C27AFA", ANSI256: "99", ANSI: "13"},
}
// DebugColors returns the entire color palette as a string
//
// Use for testing various terminals to confirm output
func DebugColors() string {
standardWidth := lipgloss.NewStyle().Width(8)
colorView := view.New(view.WithStyle(lipgloss.NewStyle().Margin(1, 0)))
colorView.Addln("Color Palette Debug").WithStyle(lipgloss.NewStyle().Bold(true))
colorView.Break()
headerStyle := standardWidth.Copy().Bold(true)
colorView.Add("Color").WithStyle(headerStyle)
colorView.Add("True").WithStyle(headerStyle)
colorView.Add("Light").WithStyle(headerStyle)
colorView.Add("Dark").WithStyle(headerStyle)
colorView.Add("ANSI256").WithStyle(headerStyle)
colorView.Add("ANSI").WithStyle(headerStyle)
v := reflect.ValueOf(*Colors)
for i := 0; i < v.NumField(); i++ {
field := v.Type().Field(i)
value := v.Field(i).Interface()
switch c := value.(type) {
case lipgloss.CompleteColor:
back := standardWidth.Copy().Align(lipgloss.Center).Background(c)
fore := standardWidth.Copy().Width(8).Foreground(c)
lightOnBack := back.Copy().Foreground(Colors.White)
darkOnBack := back.Copy().Foreground(Colors.Black)
ANSI256 := standardWidth.Copy().Align(lipgloss.Center).Background(lipgloss.Color(c.ANSI256))
ANSI := standardWidth.Copy().Align(lipgloss.Center).Background(lipgloss.Color(c.ANSI))
colorView.Add(field.Name).WithStyle(fore)
colorView.Add(field.Name).WithStyle(back)
colorView.Add(field.Name).WithStyle(lightOnBack)
colorView.Add(field.Name).WithStyle(darkOnBack)
colorView.Add(field.Name).WithStyle(ANSI256)
colorView.Add(field.Name).WithStyle(ANSI)
colorView.Break()
}
}
return colorView.Render()
}