~poldi1405/go-ansi

ref: 76d320c6afe7577b81dc9a9196484bbcad5057a9 go-ansi/style.go -rw-r--r-- 4.9 KiB
76d320c6 — Moritz Poldrack added function to remove all ANSI-Codes from a string 1 year, 5 months ago
                                                                                
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package ansi

import "fmt"

// Bold is equivalent to SetBold() + content + UnsetBold(), content will
// thereby be printed in bold.
func Bold(content ...interface{}) string {
	return SetBold() + fmt.Sprint(content...) + UnsetBold()
}

// SetBold makes the following text become bold
func SetBold() string {
	return escape + bold + set
}

// UnsetBold removes the bold property
func UnsetBold() string {
	return escape + boldOff + set
}

// Faint is equivalent to SetFaint() + content + UnsetFaint(), content will
// thereby be printed in a less intense color.
func Faint(content ...interface{}) string {
	return SetFaint() + fmt.Sprint(content...) + UnsetFaint()
}

// SetFaint makes the color of the following text less bright
func SetFaint() string {
	return escape + faint + set
}

// UnsetFaint removes the faint property
func UnsetFaint() string {
	return escape + boldOff + set
}

// Italic is equivalent to SetItalic() + content + UnsetItalic(), content will
// thereby be italic.
func Italic(content ...interface{}) string {
	return SetItalic() + fmt.Sprint(content...) + UnsetItalic()
}

// SetItalic makes the text following text become italic
func SetItalic() string {
	return escape + italic + set
}

// UnsetItalic removes the italic property
func UnsetItalic() string {
	return escape + italicOff + set
}

// Underscore is equivalent to SetUnderscore() + content + UnsetUnderscore(),
// content will thereby be underscored.
func Underscore(content ...interface{}) string {
	return SetUnderscore() + fmt.Sprint(content...) + UnsetUnderscore()
}

// SetUnderscore makes the text following become underlined
func SetUnderscore() string {
	return escape + underscore + set
}

// UnsetUnderscore removes the underscore property
func UnsetUnderscore() string {
	return escape + underscoreOff + set
}

// DoubleUnderscore is equivalent to SetDoubleUnderscore() + content +
// UnsetDoubleUnderscore(), content will thereby be double-underscored.
func DoubleUnderscore(content ...interface{}) string {
	return SetDoubleUnderscore() + fmt.Sprint(content...) + UnsetDoubleUnderscore()
}

// SetDoubleUnderscore makes the following text become underscored
func SetDoubleUnderscore() string {
	return escape + doubleUnderscore + set
}

// UnsetDoubleUnderscore removes the double-underscore attribute
func UnsetDoubleUnderscore() string {
	return escape + underscoreOff + set
}

// Blink is equivalent to SetBlink() + content + UnsetBlink(), content will
// thereby blink.
func Blink(content ...interface{}) string {
	return SetBlink() + fmt.Sprint(content...) + UnsetBlink()
}

// SetBlink makes the following text blink
func SetBlink() string {
	return escape + blink + set
}

// UnsetBlink stops the text from blinking
func UnsetBlink() string {
	return escape + blinkOff + set
}

// FastBlink is equivalent to SetFastBlink() + content + UnsetFastBlink(),
// content will thereby blink fast.
func FastBlink(content ...interface{}) string {
	return SetFastBlink() + fmt.Sprint(content...) + UnsetFastBlink()
}

// SetFastBlink makes the following text blink fast
func SetFastBlink() string {
	return escape + fastblink + set
}

// UnsetFastBlink stops the text from blinking fast
func UnsetFastBlink() string {
	return escape + fastblinkOff + set
}

// ReverseVideo is equivalent to SetReverseVideo() + content +
// UnsetReverseVideo(), content will thereby be inverted. This means that the
// background color and the foreground color will be switched.
func ReverseVideo(content ...interface{}) string {
	return SetReverseVideo() + fmt.Sprint(content...) + UnsetReverseVideo()
}

// SetReverseVideo makes the following text become inverted.
func SetReverseVideo() string {
	return escape + reverseVideo + set
}

// UnsetReverseVideo disables the inversion
func UnsetReverseVideo() string {
	return escape + reverseVideoOff + set
}

// Conceal is equivalent to SetConceal() + content + UnsetConceal(), content
// will thereby be displayed as spaces. It will still be visible if written to
// a file
func Conceal(content ...interface{}) string {
	return SetConceal() + fmt.Sprint(content...) + UnsetConceal()
}

// SetConceal conceals the following text
func SetConceal() string {
	return escape + conceal + set
}

// UnsetConceal removes the concealed property
func UnsetConceal() string {
	return escape + concealOff + set
}

// Strikethrough is equivalent to SetStrikethrough() + content +
// UnsetStrikethrough(), content will thereby be displayed as crossed out
func Strikethrough(content ...interface{}) string {
	return SetStrikethrough() + fmt.Sprint(content...) + UnsetStrikethrough()
}

// SetStrikethrough makes the following text crossed out
func SetStrikethrough() string {
	return escape + strikethrough + set
}

// UnsetStrikethrough removes the strikethrough property
func UnsetStrikethrough() string {
	return escape + strikethroughOff + set
}

// Reset clears all colors and styles (bold, underscore, blink, concealed)
func Reset() string {
	return escape + reset + set
}