-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymbols.go
89 lines (71 loc) · 1.67 KB
/
symbols.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
package logsymbols
import (
"os"
"github.com/mattn/go-isatty"
"gopkg.in/gookit/color.v1"
)
// AutodetectTTY detects if it's on a TTY output
func AutodetectTTY(f *os.File) {
if f == nil {
f = os.Stdout
}
if isatty.IsTerminal(f.Fd()) || isatty.IsCygwinTerminal(f.Fd()) {
ForceColors()
return
}
ForceNoColors()
}
// Colorize adds colors to all symbols
func Colorize(s Symbols) Symbols {
return Symbols{
Info: Symbol(color.Notice.Render(s.Info)),
Success: Symbol(color.Success.Render(s.Success)),
Ok: Symbol(color.Success.Render(s.Ok)),
Warning: Symbol(color.Warn.Render(s.Warning)),
Warn: Symbol(color.Warn.Render(s.Warn)),
Error: Symbol(color.Danger.Render(s.Error)),
}
}
// ForceColors force adding color to all symbols
func ForceColors() {
colorOn = true
setGlobals(Colorize(osBaseSymbols))
}
// ForceNoColors force removing color to all symbols
func ForceNoColors() {
colorOn = false
setGlobals(osBaseSymbols)
}
func setGlobals(s Symbols) {
Success = s.Success
Ok = s.Ok
Info = s.Info
Warning = s.Warning
Warn = s.Warn
Error = s.Error
}
// CurrentSymbols returns a set with the current OS symbols (colored if color enabled)
func CurrentSymbols() Symbols {
if colorOn {
return Colorize(osBaseSymbols)
}
return osBaseSymbols
}
// BaseSymbols returns a set with the current OS symbols
func BaseSymbols() Symbols {
return osBaseSymbols
}
// NormalSymbols returns a set with the normal symbols
func NormalSymbols() Symbols {
if colorOn {
return Colorize(normal)
}
return normal
}
// FallbackSymbols returns a set with the fallback symbols
func FallbackSymbols() Symbols {
if colorOn {
return Colorize(fallback)
}
return fallback
}