diff --git a/ui/components/pr/pr.go b/ui/components/pr/pr.go index adcf615f..1f01e18e 100644 --- a/ui/components/pr/pr.go +++ b/ui/components/pr/pr.go @@ -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), ), ) } diff --git a/ui/components/utils.go b/ui/components/utils.go index 90a8870e..72078e66 100644 --- a/ui/components/utils.go +++ b/ui/components/utils.go @@ -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)