-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolor.go
More file actions
33 lines (27 loc) · 797 Bytes
/
color.go
File metadata and controls
33 lines (27 loc) · 797 Bytes
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
package devlog
type color []byte
// ANSI color codes (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors).
var (
colorReset = color("\x1b[0m")
colorRed = color("\x1b[31m")
colorGreen = color("\x1b[32m")
colorYellow = color("\x1b[33m")
colorMagenta = color("\x1b[35m")
colorCyan = color("\x1b[36m")
colorGray = color("\x1b[37m")
noColor = color{}
)
func (handler *Handler) setColor(buffer *byteBuffer, color color) {
if handler.options.DisableColors {
return
}
buffer.write(color)
}
func (handler *Handler) resetColor(buffer *byteBuffer) {
handler.setColor(buffer, colorReset)
}
func (handler *Handler) writeByteWithColor(buffer *byteBuffer, byte byte, color color) {
handler.setColor(buffer, color)
buffer.writeByte(byte)
handler.resetColor(buffer)
}