Skip to content

Commit

Permalink
feat: add a component to format changes summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanix-Darker authored and dlvhdr committed Aug 12, 2023
1 parent 6b8dc15 commit 5425172
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ui/components/pr/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ func (pr *PullRequest) renderLines() string {
deletions = pr.Data.Deletions
}

diffs := "\033[32m+%d \033[31m-%d"
diffs := "\033[32m+%s \033[31m-%s"
return pr.getTextStyle().Render(
fmt.Sprintf(
diffs,
pr.Data.Additions,
deletions,
components.FormatNumber(pr.Data.Additions),
components.FormatNumber(deletions),
),
)
}
Expand Down
13 changes: 13 additions & 0 deletions ui/components/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ package components
import (
"fmt"
"strings"
"strconv"

"github.com/charmbracelet/lipgloss"
"github.com/dlvhdr/gh-dash/ui/context"
)

func FormatNumber(num int) string {
if num >= 1000000 {
million := float64(num) / 1000000.0
return strconv.FormatFloat(million, 'f', 1, 64) + "M"
} else if num >= 1000 {
kilo := float64(num) / 1000.0
return strconv.FormatFloat(kilo, 'f', 1, 64) + "k"
}

return strconv.Itoa(num)
}

func GetIssueTextStyle(ctx *context.ProgramContext, state string) lipgloss.Style {
if state == "OPEN" {
return lipgloss.NewStyle().Foreground(ctx.Theme.PrimaryText)
Expand Down

0 comments on commit 5425172

Please sign in to comment.