-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.go
63 lines (51 loc) · 1.58 KB
/
common.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 ui
import (
"strings"
"github.com/fatih/color"
"github.com/pterm/pterm"
"github.com/sirupsen/logrus"
)
func stopUIElements() {
StopSpinner()
}
const (
Red color.Attribute = color.FgRed
Blue color.Attribute = color.FgBlue
Magenta color.Attribute = color.FgMagenta
White color.Attribute = color.FgWhite
)
func ColorPrint(message string, fgColor color.Attribute) {
color.New(fgColor).Printf("%s", message)
}
func ColorPrintBold(message string, fgColor color.Attribute) {
color.New(fgColor, color.Bold).Printf("%s", message)
}
func Table(values [][]string) {
pterm.DefaultTable.WithHasHeader().WithData(values).Render()
}
func Success(message string) {
stopUIElements()
color.New(color.FgBlack, color.BgGreen).Printf(" SUCCESS ")
color.New(color.FgGreen).Printf(" %s\n", message)
}
func Error(message string) {
stopUIElements()
color.New(color.FgBlack, color.BgRed, color.Bold).Printf(" ERROR ")
color.New(color.FgRed).Printf(" %s\n", message)
}
func ErrorSub(message, sub string) {
stopUIElements()
color.New(color.FgBlack, color.BgRed, color.Bold).Printf(" ERROR ")
color.New(color.FgRed).Printf(" %s\n", message)
color.New(color.FgWhite, color.Bold).Printf(" > %s", sub)
}
func FatalQuiet(message string, err error) {
stopUIElements()
logrus.WithField("extended", err.Error()).Fatalln(strings.ToLower(message))
}
func Fatal(message string, err error) {
stopUIElements()
color.New(color.FgBlack, color.BgRed, color.Bold).Printf(" FATAL ")
color.New(color.FgRed).Printf(" %s\n", message)
logrus.WithField("extended", err.Error()).Fatalln(strings.ToLower(message))
}