Skip to content

Commit

Permalink
Pluralize headers according to number of available entries
Browse files Browse the repository at this point in the history
  • Loading branch information
zMoooooritz authored and muesli committed Sep 4, 2021
1 parent 01954c0 commit 23bb654
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func printBranches(branches []Branch) {
// trimmed = true
}

fmt.Println(headerStyle.Render(fmt.Sprintf("🌳 %d active branches", len(branches))))
fmt.Println(headerStyle.Render(fmt.Sprintf("%s %s", "🌳", pluralize(len(branches), "active branch", "active branches"))))

// detect max width of branch name
var maxWidth int
Expand Down
7 changes: 2 additions & 5 deletions commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,8 @@ func printCommits(repo Repo) {
if sinceTag == "" {
sinceTag = "creation"
}
if len(commits) == 0 {
fmt.Println(headerStyle.Render(fmt.Sprintf("🔥 No new commits since %s", sinceTag)))
return
}
fmt.Println(headerStyle.Render(fmt.Sprintf("🔥 %d commits since %s", len(commits), sinceTag)))

fmt.Println(headerStyle.Render(fmt.Sprintf("%s %s %s", "🔥", pluralize(len(commits), "commit since", "commits since"), sinceTag)))

// trimmed := false
if *maxCommits > 0 && len(commits) > *maxCommits {
Expand Down
2 changes: 1 addition & 1 deletion issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func printIssues(issues []Issue) {
PaddingTop(1).
Foreground(lipgloss.Color(theme.colorMagenta))

fmt.Println(headerStyle.Render(fmt.Sprintf("🐛 %d open issues", len(issues))))
fmt.Println(headerStyle.Render(fmt.Sprintf("%s %s", "🐛", pluralize(len(issues), "open issue", "open issues"))))

// trimmed := false
if *maxIssues > 0 && len(issues) > *maxIssues {
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,13 @@ func ago(t time.Time) string {

return s
}

func pluralize(count int, singular string, plural string) string {
if count == 0 {
return fmt.Sprintf("No %s", plural)
} else if count == 1 {
return fmt.Sprintf("1 %s", singular)
} else {
return fmt.Sprintf("%d %s", count, plural)
}
}
2 changes: 1 addition & 1 deletion pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func printPullRequests(prs []PullRequest) {
PaddingTop(1).
Foreground(lipgloss.Color(theme.colorMagenta))

fmt.Println(headerStyle.Render(fmt.Sprintf("📌 %d open pull requests", len(prs))))
fmt.Println(headerStyle.Render(fmt.Sprintf("%s %s", "📌", pluralize(len(prs), "open pull request", "open pull requests"))))

// trimmed := false
if *maxPullRequests > 0 && len(prs) > *maxPullRequests {
Expand Down

0 comments on commit 23bb654

Please sign in to comment.