/
display.go
67 lines (56 loc) · 1.73 KB
/
display.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
package shared
import (
"fmt"
"strings"
"github.com/andrewhsu/cli/v2/api"
"github.com/andrewhsu/cli/v2/pkg/iostreams"
"github.com/andrewhsu/cli/v2/utils"
)
func StateTitleWithColor(cs *iostreams.ColorScheme, pr api.PullRequest) string {
prStateColorFunc := cs.ColorFromString(ColorForPR(pr))
if pr.State == "OPEN" && pr.IsDraft {
return prStateColorFunc(strings.Title(strings.ToLower("Draft")))
}
return prStateColorFunc(strings.Title(strings.ToLower(pr.State)))
}
func ColorForPR(pr api.PullRequest) string {
if pr.State == "OPEN" && pr.IsDraft {
return "gray"
}
return ColorForState(pr.State)
}
// ColorForState returns a color constant for a PR/Issue state
func ColorForState(state string) string {
switch state {
case "OPEN":
return "green"
case "CLOSED":
return "red"
case "MERGED":
return "magenta"
default:
return ""
}
}
func PrintHeader(io *iostreams.IOStreams, s string) {
fmt.Fprintln(io.Out, io.ColorScheme().Bold(s))
}
func PrintMessage(io *iostreams.IOStreams, s string) {
fmt.Fprintln(io.Out, io.ColorScheme().Gray(s))
}
func ListHeader(repoName string, itemName string, matchCount int, totalMatchCount int, hasFilters bool) string {
if totalMatchCount == 0 {
if hasFilters {
return fmt.Sprintf("No %ss match your search in %s", itemName, repoName)
}
return fmt.Sprintf("There are no open %ss in %s", itemName, repoName)
}
if hasFilters {
matchVerb := "match"
if totalMatchCount == 1 {
matchVerb = "matches"
}
return fmt.Sprintf("Showing %d of %s in %s that %s your search", matchCount, utils.Pluralize(totalMatchCount, itemName), repoName, matchVerb)
}
return fmt.Sprintf("Showing %d of %s in %s", matchCount, utils.Pluralize(totalMatchCount, fmt.Sprintf("open %s", itemName)), repoName)
}