Skip to content

Commit f0e2636

Browse files
committed
table output revamp
1 parent 88b5dd2 commit f0e2636

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

internal/cmd/output.go

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,41 @@ func displayTableStats(stats *StatsCollector) {
8787
}
8888
if repoStat.SkippedCriteria > 0 {
8989
dnmColor = yellow
90-
}
90+
}
91+
92+
// Construct skipped text without color codes first to get proper width
9193
mcRaw := fmt.Sprintf("%d", repoStat.SkippedMergeConf)
9294
dnmRaw := fmt.Sprintf("%d", repoStat.SkippedCriteria)
93-
skippedRaw := fmt.Sprintf("%s (MC), %s (DNM)", mcRaw, dnmRaw)
94-
skippedPadded := fmt.Sprintf("%-*s", colWidths[2], skippedRaw)
95-
mcIdx := strings.Index(skippedPadded, mcRaw)
96-
dnmIdx := strings.Index(skippedPadded, dnmRaw)
97-
skippedColored := skippedPadded
98-
if mcIdx != -1 {
99-
skippedColored = skippedColored[:mcIdx] + colorize(mcRaw, mcColor) + skippedColored[mcIdx+len(mcRaw):]
95+
skippedPlain := fmt.Sprintf("%s (MC), %s (DNM)", mcRaw, dnmRaw)
96+
97+
// Then add color codes for display
98+
skippedDisplay := ""
99+
if noColor {
100+
skippedDisplay = skippedPlain
101+
} else {
102+
mcDisplay := mcColor + mcRaw + reset
103+
dnmDisplay := dnmColor + dnmRaw + reset
104+
skippedDisplay = fmt.Sprintf("%s (MC), %s (DNM)", mcDisplay, dnmDisplay)
100105
}
101-
if dnmIdx != -1 {
102-
dnmIdx = strings.Index(skippedColored, dnmRaw)
103-
skippedColored = skippedColored[:dnmIdx] + colorize(dnmRaw, dnmColor) + skippedColored[dnmIdx+len(dnmRaw):]
106+
107+
// Ensure proper padding based on the plaintext width
108+
paddingLen := colWidths[2] - len(skippedPlain)
109+
padding := ""
110+
if paddingLen > 0 {
111+
padding = strings.Repeat(" ", paddingLen)
104112
}
113+
105114
statusColored := colorize(status, statusColor)
106-
statusColored = fmt.Sprintf("%-*s", colWidths[3]+len(statusColored)-len(status), statusColored)
115+
statusPadding := colWidths[3] - len(status)
116+
if statusPadding > 0 {
117+
statusColored += strings.Repeat(" ", statusPadding)
118+
}
107119

108120
fmt.Printf(
109-
"│ %-*s │ %s │ %s │ %s │\n",
121+
"│ %-*s │ %*d%s%s │ %s │\n",
110122
repoCol, repoStat.RepoName,
111-
fmt.Sprintf("%*d", colWidths[1], repoStat.CombinedCount),
112-
skippedColored,
123+
colWidths[1], repoStat.CombinedCount,
124+
skippedDisplay, padding,
113125
statusColored,
114126
)
115127
}
@@ -119,12 +131,39 @@ func displayTableStats(stats *StatsCollector) {
119131
summaryTop := "╭───────────────┬───────────────┬───────────────────────┬───────────────╮"
120132
summaryHead := "│ Repos │ Combined PRs │ Skipped │ Total PRs │"
121133
summarySep := "├───────────────┼───────────────┼───────────────────────┼───────────────┤"
122-
skippedRaw := fmt.Sprintf("%d (MC), %d (DNM)", stats.PRsSkippedMergeConflict, stats.PRsSkippedCriteria)
134+
135+
// Use the same approach for summary table to ensure consistency
136+
mcSummaryRaw := fmt.Sprintf("%d", stats.PRsSkippedMergeConflict)
137+
dnmSummaryRaw := fmt.Sprintf("%d", stats.PRsSkippedCriteria)
138+
139+
skippedSummaryPlain := fmt.Sprintf("%s (MC), %s (DNM)", mcSummaryRaw, dnmSummaryRaw)
140+
skippedSummaryDisplay := skippedSummaryPlain
141+
if !noColor {
142+
mcColor := green
143+
dnmColor := green
144+
if stats.PRsSkippedMergeConflict > 0 {
145+
mcColor = yellow
146+
}
147+
if stats.PRsSkippedCriteria > 0 {
148+
dnmColor = yellow
149+
}
150+
mcDisplay := mcColor + mcSummaryRaw + reset
151+
dnmDisplay := dnmColor + dnmSummaryRaw + reset
152+
skippedSummaryDisplay = fmt.Sprintf("%s (MC), %s (DNM)", mcDisplay, dnmDisplay)
153+
}
154+
155+
summarySkippedPadding := 21 - len(skippedSummaryPlain)
156+
summaryPadding := ""
157+
if summarySkippedPadding > 0 {
158+
summaryPadding = strings.Repeat(" ", summarySkippedPadding)
159+
}
160+
123161
summaryRow := fmt.Sprintf(
124-
"│ %-13d │ %-13d │ %-21s │ %-13d │",
162+
"│ %-13d │ %-13d │ %s%s │ %-13d │",
125163
stats.ReposProcessed,
126164
stats.PRsCombined,
127-
skippedRaw,
165+
skippedSummaryDisplay,
166+
summaryPadding,
128167
len(stats.CombinedPRLinks),
129168
)
130169
summaryBot := "╰───────────────┴───────────────┴───────────────────────┴───────────────╯"

0 commit comments

Comments
 (0)