forked from muesli/gitty
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathissue.go
64 lines (54 loc) · 1.66 KB
/
issue.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
package main
import (
"fmt"
"strconv"
"strings"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/gitty/vcs"
"github.com/muesli/reflow/truncate"
)
func printIssue(issue vcs.Issue, maxWidth int) string {
genericStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGray))
numberStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorBlue)).Width(maxWidth).Align(lipgloss.Right)
timeStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorGreen)).Width(8).Align(lipgloss.Right)
titleStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color(theme.colorDarkGray)).Width(80 - maxWidth)
var s string
s += numberStyle.Render(strconv.Itoa(issue.ID))
s += genericStyle.Render(" ")
s += titleStyle.Render(truncate.StringWithTail(issue.Title, uint(80-maxWidth), "…"))
s += genericStyle.Render(" ")
s += timeStyle.Render(ago(issue.CreatedAt))
s += genericStyle.Render(" ")
s += issue.Labels.View()
return s
}
func printIssues(issues []vcs.Issue) string {
var s strings.Builder
headerStyle := lipgloss.NewStyle().
PaddingTop(1).
Foreground(lipgloss.Color(theme.colorMagenta))
s.WriteString(headerStyle.Render(fmt.Sprintf("%s %s", "🐛", pluralize(len(issues), "open issue", "open issues"))))
// trimmed := false
if *maxIssues > 0 && len(issues) > *maxIssues {
issues = issues[:*maxIssues]
// trimmed = true
}
// detect max width of issue number
var maxWidth int
for _, v := range issues {
if len(strconv.Itoa(v.ID)) > maxWidth {
maxWidth = len(strconv.Itoa(v.ID))
}
}
for _, v := range issues {
s.WriteString(printIssue(v, maxWidth))
}
// if trimmed {
// fmt.Println("...")
// }
return s.String()
}