-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
issue.go
61 lines (51 loc) · 1.58 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
package main
import (
"fmt"
"strconv"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/gitty/vcs"
"github.com/muesli/reflow/truncate"
)
func printIssue(issue vcs.Issue, maxWidth int) {
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()
fmt.Println(s)
}
func printIssues(issues []vcs.Issue) {
headerStyle := lipgloss.NewStyle().
PaddingTop(1).
Foreground(lipgloss.Color(theme.colorMagenta))
fmt.Println(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 {
printIssue(v, maxWidth)
}
// if trimmed {
// fmt.Println("...")
// }
}