/
ui.go
83 lines (61 loc) · 1.59 KB
/
ui.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
package cmd
import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/antham/gommit/gommit"
)
var failure = func(err error) {
color.Red(err.Error())
}
var success = func(message string) {
color.Green(message)
}
var info = func(message string) {
color.Cyan(message)
}
var renderMatchings = func(matchings *[]*gommit.Matching) {
for _, m := range *matchings {
color.White("----")
fmt.Println()
if ID, ok := m.Context["ID"]; ok {
fmt.Printf("%s%s\n", color.YellowString("Id : "), color.WhiteString("%s", ID))
}
if message, ok := m.Context["message"]; ok {
color.Yellow("Message : ")
for _, field := range strings.Split(message, "\n") {
fmt.Printf("%s%s\n", color.YellowString(" "), color.WhiteString("%s", field))
}
}
fmt.Println()
errs := []error{}
if m.MessageError != nil {
errs = append(errs, m.MessageError)
}
if m.SummaryError != nil {
errs = append(errs, m.SummaryError)
}
for i, e := range errs {
if i == 0 {
fmt.Printf("%s", color.YellowString("Error(s) : "))
fmt.Printf("- %s\n", color.RedString("%s", e.Error()))
} else {
fmt.Printf(" - %s\n", color.RedString("%s", e.Error()))
}
}
fmt.Println()
}
}
var renderExamples = func(examples map[string]string) {
color.White("=======")
fmt.Println()
color.White("Your message must match one of those following patterns :")
fmt.Println()
for key, example := range examples {
color.White("----")
fmt.Println()
color.Yellow("%s : ", strings.Replace(strings.Title(key), "_", " ", -1))
fmt.Println()
color.Cyan("%s", example)
}
}