-
Notifications
You must be signed in to change notification settings - Fork 0
/
style.go
143 lines (119 loc) · 2.93 KB
/
style.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
// Package consolestyle provides functions to style text printed to the console.
package consolestyle
import "strings"
// styled represents a styled string with a fluent api.
type styled struct {
lines []string
value string
}
// Style creates a new styled fluent interface.
func Style(value string) *styled {
var lines []string
return &styled{lines, value}
}
// Red styles the string with red color.
func (s *styled) Red() *styled {
s.value = Red(s.value)
return s
}
// Green styles the string with green color.
func (s *styled) Green() *styled {
s.value = Green(s.value)
return s
}
// Yellow styles the string with yellow color.
func (s *styled) Yellow() *styled {
s.value = Yellow(s.value)
return s
}
// Blue styles the string with blue color.
func (s *styled) Blue() *styled {
s.value = Blue(s.value)
return s
}
// Magenta styles the string with magenta color.
func (s *styled) Magenta() *styled {
s.value = Magenta(s.value)
return s
}
// Cyan styles the string with cyan color.
func (s *styled) Cyan() *styled {
s.value = Cyan(s.value)
return s
}
// BgRed styles the string with red background.
func (s *styled) BgRed() *styled {
s.value = BgRed(s.value)
return s
}
// BgGreen styles the string with green background.
func (s *styled) BgGreen() *styled {
s.value = BgGreen(s.value)
return s
}
// BgYellow styles the string with yellow background.
func (s *styled) BgYellow() *styled {
s.value = BgYellow(s.value)
return s
}
// BgBlue styles the string with blue background.
func (s *styled) BgBlue() *styled {
s.value = BgBlue(s.value)
return s
}
// BgMagenta styles the string with magenta background.
func (s *styled) BgMagenta() *styled {
s.value = BgMagenta(s.value)
return s
}
// BgCyan styles the string with cyan background.
func (s *styled) BgCyan() *styled {
s.value = BgCyan(s.value)
return s
}
// Inverse inverts the string.
func (s *styled) Inverse() *styled {
s.value = Inverse(s.value)
return s
}
// Bold makes the string bold.
func (s *styled) Bold() *styled {
s.value = Bold(s.value)
return s
}
// Dim makes the string dim.
func (s *styled) Dim() *styled {
s.value = Dim(s.value)
return s
}
// Italic makes the string italic.
func (s *styled) Italic() *styled {
s.value = Italic(s.value)
return s
}
// Underline underlines the string.
func (s *styled) Underline() *styled {
s.value = Underline(s.value)
return s
}
// Strike strikes through the string.
func (s *styled) Strike() *styled {
s.value = Strike(s.value)
return s
}
// NewLine adds a new line with the provided value to the styled string.
func (s *styled) NewLine(value string) *styled {
s.lines = append(s.lines, s.value)
s.value = value
return s
}
// EmptyLine adds an empty line to the styled string.
func (s *styled) EmptyLine() *styled {
s.lines = append(s.lines, s.value)
s.value = ""
return s
}
// String returns the styled string with formatting applied.
func (s *styled) String() string {
return strings.Join(append(s.lines, s.value), "\n")
}