-
Notifications
You must be signed in to change notification settings - Fork 5
/
styles.go
144 lines (126 loc) Β· 3.42 KB
/
styles.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package fzf
import "github.com/charmbracelet/lipgloss"
var (
defaultColor = "#00ADD8"
defaultStylesOption = stylesOption{
prompt: lipgloss.NewStyle(),
inputPlaceholder: lipgloss.NewStyle().Faint(true),
inputText: lipgloss.NewStyle(),
cursor: lipgloss.NewStyle().Foreground(lipgloss.Color(defaultColor)),
cursorLine: lipgloss.NewStyle().Bold(true),
matches: lipgloss.NewStyle().Foreground(lipgloss.Color(defaultColor)),
selectedPrefix: lipgloss.NewStyle().Foreground(lipgloss.Color(defaultColor)),
unselectedPrefix: lipgloss.NewStyle().Faint(true),
}
)
// Style represents a style.
type Style struct {
ForegroundColor string
BackgroundColor string
Bold bool
Blink bool
Italic bool
Strikethrough bool
Underline bool
Faint bool
}
// Styles is the styles for each component.
type Styles struct {
option *stylesOption
}
func (s *Style) lipgloss() lipgloss.Style {
style := lipgloss.NewStyle()
if s.ForegroundColor != "" {
style = style.Foreground(lipgloss.Color(s.ForegroundColor))
}
if s.BackgroundColor != "" {
style = style.Background(lipgloss.Color(s.BackgroundColor))
}
if s.Bold {
style = style.Bold(true)
}
if s.Blink {
style = style.Blink(true)
}
if s.Italic {
style = style.Italic(true)
}
if s.Strikethrough {
style = style.Strikethrough(true)
}
if s.Underline {
style = style.Underline(true)
}
if s.Faint {
style = style.Faint(true)
}
return style
}
// Option represents a option for the styles.
type StylesOption func(o *stylesOption)
type stylesOption struct {
prompt lipgloss.Style
inputPlaceholder lipgloss.Style
inputText lipgloss.Style
cursor lipgloss.Style
cursorLine lipgloss.Style
selectedPrefix lipgloss.Style
unselectedPrefix lipgloss.Style
matches lipgloss.Style
}
// NewStyles returns a new styles.
func NewStyles(opts ...StylesOption) *Styles {
o := defaultStylesOption
for _, opt := range opts {
opt(&o)
}
return &Styles{option: &o}
}
// WithStylePrompt sets the style of prompt.
func WithStylePrompt(s Style) StylesOption {
return func(o *stylesOption) {
o.prompt = s.lipgloss()
}
}
// WithInputPlaceholder sets the style of placeholder for input.
func WithStyleInputPlaceholder(s Style) StylesOption {
return func(o *stylesOption) {
o.inputPlaceholder = s.lipgloss()
}
}
// WithStyleInputText sets the style of input text.
func WithStyleInputText(s Style) StylesOption {
return func(o *stylesOption) {
o.inputText = s.lipgloss()
}
}
// WithStyleCursor sets the style of cursor.
func WithStyleCursor(s Style) StylesOption {
return func(o *stylesOption) {
o.cursor = s.lipgloss()
}
}
// WithStyleCursorLine sets the style of cursor line.
func WithStyleCursorLine(s Style) StylesOption {
return func(o *stylesOption) {
o.cursorLine = s.lipgloss()
}
}
// WithStyleSelectedPrefix sets the style of prefix of the selected item.
func WithStyleSelectedPrefix(s Style) StylesOption {
return func(o *stylesOption) {
o.selectedPrefix = s.lipgloss()
}
}
// WithStyleUnselectedPrefix sets the style of prefix of the unselected item.
func WithStyleUnselectedPrefix(s Style) StylesOption {
return func(o *stylesOption) {
o.unselectedPrefix = s.lipgloss()
}
}
// WithStyleMatches sets the style of the matched characters.
func WithStyleMatches(s Style) StylesOption {
return func(o *stylesOption) {
o.matches = s.lipgloss()
}
}