-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
98 lines (82 loc) · 1.79 KB
/
logger.go
File metadata and controls
98 lines (82 loc) · 1.79 KB
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
package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
)
type colorFunction func(...string) string
func color(color string) colorFunction {
return lipgloss.NewStyle().Foreground(lipgloss.Color(color)).Render
}
// var (
// red = color("1")
// green = color("2")
// yellow = color("3")
// blue = color("4")
// magenta = color("5")
// cyan = color("6")
// gray = color("7")
// black = color("8")
// light_red = color("9")
// light_green = color("10")
// light_yellow = color("11")
// light_blue = color("12")
// light_magenta = color("13")
// light_cyan = color("14")
// white = color("15")
// )
var (
base = color("#5d98d3")
base2 = color("#5eacf9")
dim = color("#d7ffae")
accent = color("#f7e165")
accent2 = color("#a95ef9")
success = color("#1bfcc4")
err = color("#e53939")
err2 = color("#f49c3d")
)
type Logger struct {
silent bool
}
func (l *Logger) setSilent(silent bool) {
l.silent = silent
}
func (l *Logger) Instruction(kind string, args ...string) {
var pickColor colorFunction
switch kind {
case "launch":
pickColor = base2
case "stop":
pickColor = base2
default:
pickColor = base
}
// Combine the 'kind' and 'args' formatted
result := pickColor(kind) + pickColor("(")
for i, arg := range args {
result += accent(arg)
if i < len(args)-1 {
result += pickColor(",")
}
}
result += pickColor(")")
switch kind {
case "expect":
fmt.Print(result)
default:
fmt.Println(result)
}
}
func (l *Logger) Loading() {
fmt.Print(dim("."))
}
func (l *Logger) OK() {
fmt.Println(success(" OK"))
}
func (l *Logger) Error(severe bool) {
if severe {
fmt.Println(err(" ERROR"))
} else {
fmt.Println(err2(" ERROR"))
}
}
var Log = Logger{silent: false}