/
sytle.go
103 lines (88 loc) · 1.96 KB
/
sytle.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 2021. thzll <tanghuizll@gmail.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
package termuix
// Color represents a color.
type Color int32
// Common colors.
const (
ColorDefault Color = iota
//ColorBlack
//ColorWhite
//ColorRed
//ColorGreen
//ColorBlue
//ColorCyan
//ColorMagenta
//ColorYellow
ColorBlack Color = 0
ColorRed Color = 1
ColorGreen Color = 2
ColorYellow Color = 3
ColorBlue Color = 4
ColorMagenta Color = 5
ColorCyan Color = 6
ColorWhite Color = 7
)
// Decoration represents a bold/underline/etc. state
type Decoration int
// Decoration modes: Inherit from parent widget, explicitly on, or explicitly off.
const (
DecorationInherit Decoration = iota
DecorationOn
DecorationOff
)
const ColorClear Color = -1
type Modifier uint
const (
// ModifierClear clears any modifiers
ModifierClear Modifier = 0
ModifierBold Modifier = 1 << 9
ModifierUnderline Modifier = 1 << 10
ModifierReverse Modifier = 1 << 11
)
// Style determines how a cell should be painted.
// The zero value uses default from
type Style struct {
Fg Color
Bg Color
Modifier Modifier
}
var StyleClear = Style{
Fg: ColorClear,
Bg: ColorClear,
Modifier: ModifierClear,
}
// NewStyle takes 1 to 3 arguments
// 1st argument = Fg
// 2nd argument = optional Bg
// 3rd argument = optional Modifier
func NewStyle(fg Color, args ...interface{}) Style {
bg := ColorClear
modifier := ModifierClear
if len(args) >= 1 {
bg = args[0].(Color)
}
if len(args) == 2 {
modifier = args[1].(Modifier)
}
return Style{
fg,
bg,
modifier,
}
}
func (s *Style) SetModifier(m Modifier) {
s.Modifier = m
}
// mergeIn returns the receiver Style, with any changes in delta applied.
func (s Style) mergeIn(delta Style) Style {
result := s
if delta.Fg != ColorDefault {
result.Fg = delta.Fg
}
if delta.Bg != ColorDefault {
result.Bg = delta.Bg
}
return result
}