-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgostyle.go
207 lines (168 loc) · 5.23 KB
/
gostyle.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package gostyle
import "fmt"
// gostyle represents the style library
type gostyle struct{}
// New creates a new instance of the gostyle library
func New() *gostyle {
return &gostyle{}
}
// ApplyBlink applies the blink effect to the given message
func (gs *gostyle) ApplyBlink(msg string) string {
return fmt.Sprintf("\x1b[5m%s\x1b[0m", msg) // Start blink, then reset
}
// ApplyReverse applies the reverse effect to the given message
func (gs *gostyle) ApplyReverse(msg string) string {
return fmt.Sprintf("\x1b[7m%s\x1b[0m", msg) // Start reverse, then reset
}
// ApplyHidden applies the hidden effect to the given message
func (gs *gostyle) ApplyHidden(msg string) string {
return fmt.Sprintf("\x1b[8m%s\x1b[0m", msg) // Start hidden, then reset
}
// LogInfo prints an informational message with a yellow prefix
func (gs *gostyle) LogInfo(msg string) string {
return gs.Log("[!] ", "33", msg) // Yellow
}
// LogQue prints a question message with a cyan prefix
func (gs *gostyle) LogQue(msg string) string {
return gs.Log("[?] ", "36", msg) // Cyan
}
// LogBad prints a bad message with a red prefix
func (gs *gostyle) LogBad(msg string) string {
return gs.Log("[-] ", "31", msg) // Red
}
// LogGood prints a good message with a green prefix
func (gs *gostyle) LogGood(msg string) string {
return gs.Log("[+] ", "32", msg) // Green
}
// LogRun prints a running message with a blue prefix
func (gs *gostyle) LogRun(msg string) string {
return gs.Log("[~] ", "34", msg) // Blue
}
// Log prints a log message with the given prefix, color code, and message
func (gs *gostyle) Log(prefix, colorCode, msg string) string {
// Construct and return the styled log message
return fmt.Sprintf("\x1b[%sm%s\x1b[0m%s", colorCode, prefix, msg)
}
func (gs *gostyle) Inf() string {
return fmt.Sprintf("[%s]", gs.Blue("INF"))
}
func (gs *gostyle) Err() string {
return fmt.Sprintf("[%s]", gs.Red("ERR"))
}
func (gs *gostyle) Wrn() string {
return fmt.Sprintf("[%s]", gs.Yellow("WRN"))
}
func (gs *gostyle) Act() string {
return fmt.Sprintf("[%s]", gs.BrGreen("ACT"))
}
// Define color functions
func (gs *gostyle) Black(msg string) string {
return fmt.Sprintf("\x1b[30m%s\x1b[0m", msg)
}
func (gs *gostyle) Red(msg string) string {
return fmt.Sprintf("\x1b[31m%s\x1b[0m", msg)
}
func (gs *gostyle) Green(msg string) string {
return fmt.Sprintf("\x1b[32m%s\x1b[0m", msg)
}
func (gs *gostyle) Yellow(msg string) string {
return fmt.Sprintf("\x1b[33m%s\x1b[0m", msg)
}
func (gs *gostyle) Blue(msg string) string {
return fmt.Sprintf("\x1b[34m%s\x1b[0m", msg)
}
func (gs *gostyle) Magenta(msg string) string {
return fmt.Sprintf("\x1b[35m%s\x1b[0m", msg)
}
func (gs *gostyle) Cyan(msg string) string {
return fmt.Sprintf("\x1b[36m%s\x1b[0m", msg)
}
func (gs *gostyle) Gray(msg string) string {
return fmt.Sprintf("\x1b[37m%s\x1b[0m", msg)
}
func (gs *gostyle) White(msg string) string {
return fmt.Sprintf("\x1b[97m%s\x1b[0m", msg)
}
// Define bright color functions
func (gs *gostyle) BrBlack(msg string) string {
return fmt.Sprintf("\x1b[90m%s\x1b[0m", msg)
}
func (gs *gostyle) BrRed(msg string) string {
return fmt.Sprintf("\x1b[91m%s\x1b[0m", msg)
}
func (gs *gostyle) BrGreen(msg string) string {
return fmt.Sprintf("\x1b[92m%s\x1b[0m", msg)
}
func (gs *gostyle) BrYellow(msg string) string {
return fmt.Sprintf("\x1b[93m%s\x1b[0m", msg)
}
func (gs *gostyle) BrBlue(msg string) string {
return fmt.Sprintf("\x1b[94m%s\x1b[0m", msg)
}
func (gs *gostyle) BrMagenta(msg string) string {
return fmt.Sprintf("\x1b[95m%s\x1b[0m", msg)
}
func (gs *gostyle) BrCyan(msg string) string {
return fmt.Sprintf("\x1b[96m%s\x1b[0m", msg)
}
func (gs *gostyle) BrGray(msg string) string {
return fmt.Sprintf("\x1b[97m%s\x1b[0m", msg)
}
// Define text style functions
func (gs *gostyle) Bold(msg string) string {
return fmt.Sprintf("\x1b[1m%s\x1b[0m", msg)
}
func (gs *gostyle) Italic(msg string) string {
return fmt.Sprintf("\x1b[3m%s\x1b[0m", msg)
}
func (gs *gostyle) Underline(msg string) string {
return fmt.Sprintf("\x1b[4m%s\x1b[0m", msg)
}
func (gs *gostyle) Dim(msg string) string {
return fmt.Sprintf("\x1b[2m%s\x1b[0m", msg)
}
func (gs *gostyle) Strike(msg string) string {
return fmt.Sprintf("\x1b[9m%s\x1b[0m", msg)
}
// BGround applies background color to the given message
// Color parameter should be one of the available color strings
func (gs *gostyle) BGround(msg string, color string) string {
var colorCode int
switch color {
case "black":
colorCode = 40
case "red":
colorCode = 41
case "green":
colorCode = 42
case "yellow":
colorCode = 43
case "blue":
colorCode = 44
case "magenta":
colorCode = 45
case "cyan":
colorCode = 46
case "white":
colorCode = 47
case "BrBlack":
colorCode = 90
case "BrRed":
colorCode = 91
case "BrGreen":
colorCode = 92
case "BrYellow":
colorCode = 93
case "BrBlue":
colorCode = 94
case "BrMagenta":
colorCode = 95
case "BrCyan":
colorCode = 96
case "BrWhite":
colorCode = 97
default:
return msg // Return message as is if color not recognized
}
return fmt.Sprintf("\x1b[%dm%s\x1b[0m", colorCode, msg)
}