Skip to content

Commit d2726ec

Browse files
authored
Merge pull request #76 from adeeshperera/main
fix #72 : Replace hardcoded display limits with named constants in ShowFileStatistics
2 parents 546d92e + 2520073 commit d2726ec

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

internal/display/display.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import (
66
"github.com/pterm/pterm"
77
)
88

9+
const (
10+
MaxStagedFiles = 5
11+
MaxUnstagedFiles = 3
12+
MaxUntrackedFiles = 3
13+
)
14+
915
// FileStatistics holds statistics about changed files
1016
type FileStatistics struct {
1117
StagedFiles []string
@@ -31,17 +37,17 @@ func ShowFileStatistics(stats *FileStatistics) {
3137
BulletStyle: pterm.NewStyle(pterm.FgGreen),
3238
})
3339
for i, file := range stats.StagedFiles {
34-
if i < 5 { // Show first 5 files
40+
if i < MaxStagedFiles { // Show first 5 files
3541
bulletItems = append(bulletItems, pterm.BulletListItem{
3642
Level: 1,
3743
Text: file,
3844
})
3945
}
4046
}
41-
if len(stats.StagedFiles) > 5 {
47+
if len(stats.StagedFiles) > MaxStagedFiles {
4248
bulletItems = append(bulletItems, pterm.BulletListItem{
4349
Level: 1,
44-
Text: pterm.Gray(fmt.Sprintf("... and %d more", len(stats.StagedFiles)-5)),
50+
Text: pterm.Gray(fmt.Sprintf("... and %d more", len(stats.StagedFiles)-MaxStagedFiles)),
4551
})
4652
}
4753
}
@@ -54,17 +60,17 @@ func ShowFileStatistics(stats *FileStatistics) {
5460
BulletStyle: pterm.NewStyle(pterm.FgYellow),
5561
})
5662
for i, file := range stats.UnstagedFiles {
57-
if i < 3 {
63+
if i < MaxUnstagedFiles {
5864
bulletItems = append(bulletItems, pterm.BulletListItem{
5965
Level: 1,
6066
Text: file,
6167
})
6268
}
6369
}
64-
if len(stats.UnstagedFiles) > 3 {
70+
if len(stats.UnstagedFiles) > MaxUnstagedFiles {
6571
bulletItems = append(bulletItems, pterm.BulletListItem{
6672
Level: 1,
67-
Text: pterm.Gray(fmt.Sprintf("... and %d more", len(stats.UnstagedFiles)-3)),
73+
Text: pterm.Gray(fmt.Sprintf("... and %d more", len(stats.UnstagedFiles)-MaxUnstagedFiles)),
6874
})
6975
}
7076
}
@@ -77,17 +83,17 @@ func ShowFileStatistics(stats *FileStatistics) {
7783
BulletStyle: pterm.NewStyle(pterm.FgCyan),
7884
})
7985
for i, file := range stats.UntrackedFiles {
80-
if i < 3 {
86+
if i < MaxUntrackedFiles {
8187
bulletItems = append(bulletItems, pterm.BulletListItem{
8288
Level: 1,
8389
Text: file,
8490
})
8591
}
8692
}
87-
if len(stats.UntrackedFiles) > 3 {
93+
if len(stats.UntrackedFiles) > MaxUntrackedFiles {
8894
bulletItems = append(bulletItems, pterm.BulletListItem{
8995
Level: 1,
90-
Text: pterm.Gray(fmt.Sprintf("... and %d more", len(stats.UntrackedFiles)-3)),
96+
Text: pterm.Gray(fmt.Sprintf("... and %d more", len(stats.UntrackedFiles)-MaxUntrackedFiles)),
9197
})
9298
}
9399
}

0 commit comments

Comments
 (0)