-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
68 lines (58 loc) · 1.44 KB
/
util.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
package main
import (
"fmt"
"log"
"sync"
)
const (
ANSI_RESET = "\x1b[0m"
ANSI_RED = "\x1b[31m"
ANSI_GREEN = "\x1b[32m"
ANSI_YELLOW = "\x1b[33m"
ANSI_BLUE = "\x1b[34m"
ANSI_MAGENTA = "\x1b[35m"
ANSI_CYAN = "\x1b[36m"
ANSI_RED_BRIGHT = "\x1b[91m"
ANSI_YELLOW_BRIGHT = "\x1b[93m"
ANSI_CYAN_BRIGHT = "\x1b[96m"
)
var colors = []string{
ANSI_BLUE,
ANSI_MAGENTA,
ANSI_GREEN,
ANSI_CYAN,
ANSI_YELLOW,
ANSI_RED,
}
var wg sync.WaitGroup
// prints not empty text with color to allow the user to separate the output of different commands.
// index is used to select a color, therefore a maximum of 6 commands can be executed in parallel
func commandPrint(index int, text string) {
i := func() string {
if index < 9 {
return fmt.Sprintf("0%d", index)
}
return fmt.Sprint(index)
}()
if CONFIG.SurpressOutput {
return
}
if CONFIG.ColorOutput {
if CONFIG.OnlyColorPrefix {
log.Printf("%s%s |%s %s\n", colors[index%len(colors)], i, ANSI_RESET, text)
return
}
log.Printf("%s%s | %s%s\n", colors[index%len(colors)], i, text, ANSI_RESET)
} else {
log.Printf("%s | %s\n", i, text)
}
}
func logInfo(text string) {
log.Printf("%sinfo%s: %s\n", ANSI_CYAN_BRIGHT, ANSI_RESET, text)
}
func logWarn(text string) {
log.Printf("%swarn%s: %s\n", ANSI_YELLOW_BRIGHT, ANSI_RESET, text)
}
func logErr(text string) {
log.Fatalf("%serr%s: %s\n", ANSI_RED_BRIGHT, ANSI_RESET, text)
}