Skip to content

Commit 8368e01

Browse files
authored
Merge pull request #38 from hrtsegv/dynamically-adjust-cell-width
refactor printCell function to dynamically adjust cell width based on max value
2 parents 3148858 + 77883bd commit 8368e01

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

print.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,15 @@ func printTable(commits map[int]int, b Boundary) {
6666
}
6767

6868
func printCell(val, maxValue int) string {
69+
digitWidth := 1
70+
if maxValue > 0 {
71+
digitWidth = len(fmt.Sprintf("%d", maxValue))
72+
}
73+
6974
var colorFunc color.Style
7075
if val == 0 {
7176
colorFunc = color.New(color.FgLightWhite, color.BgBlack)
72-
return colorFunc.Sprintf(" - ")
77+
return colorFunc.Sprintf(" %*s ", digitWidth, "-")
7378
}
7479

7580
if maxValue <= 0 {
@@ -85,7 +90,7 @@ func printCell(val, maxValue int) string {
8590
} else {
8691
colorFunc = color.New(color.FgBlack, color.BgBlue)
8792
}
88-
return colorFunc.Sprintf(" %2d ", val)
93+
return colorFunc.Sprintf(" %*d ", digitWidth, val)
8994
}
9095

9196
func printLegend(max int) {

0 commit comments

Comments
 (0)