-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
63 lines (51 loc) · 1.27 KB
/
log.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
package main
import (
"fmt"
"strings"
)
const (
colorGreen = "\033[0;32m"
colorBlue = "\033[0;34m"
colorRed = "\033[0;31m"
colorOrange = "\033[0;33m"
colorGray = "\033[0;37m"
colorReset = "\033[0m"
)
const (
symbolPositive = ""
symbolInfo = ""
symbolNegative = ""
symbolQuestion = ""
)
type Log struct{}
func NewLogUtil() *Log {
return &Log{}
}
func (l *Log) formatMessage(symbol, color, message string) string {
const separator = " "
return fmt.Sprintf("%s%s%s%s%s\n", color, symbol, separator, message, colorReset)
}
func (l *Log) Positive(message string) {
fmt.Print(l.formatMessage(symbolPositive, colorGreen, message))
}
func (l *Log) Info(message string) {
fmt.Print(l.formatMessage(symbolInfo, colorBlue, message))
}
func (l *Log) Neutral(message string) {
fmt.Print(l.formatMessage(" ", colorGray, message))
}
func (l *Log) Negative(message string, err error) {
fmt.Print(l.formatMessage(symbolNegative, colorRed, message))
if err != nil {
fmt.Println(err)
}
}
func (l *Log) Question(message string) {
fmt.Print(l.formatMessage(symbolQuestion, colorOrange, message))
}
func (l *Log) Ask(s string) bool {
var response string
l.Question(fmt.Sprintf("%s (y/N): ", s))
fmt.Scanln(&response)
return strings.ToLower(response) == "y"
}