Skip to content

Commit 87d6215

Browse files
committed
fixes
1 parent 9a65dad commit 87d6215

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

internal/cmd/root.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"strings"
89
"time"
910

1011
"github.com/cli/go-gh/v2/pkg/api"
@@ -494,7 +495,7 @@ func displayTableStats(stats *StatsCollector) {
494495
status = "NOT ENOUGH"
495496
statusColor = yellow
496497
}
497-
498+
498499
mcColor := green
499500
dnmColor := green
500501
if repoStat.SkippedMergeConf > 0 {
@@ -506,22 +507,25 @@ func displayTableStats(stats *StatsCollector) {
506507
mcRaw := fmt.Sprintf("%d", repoStat.SkippedMergeConf)
507508
dnmRaw := fmt.Sprintf("%d", repoStat.SkippedCriteria)
508509
skippedRaw := fmt.Sprintf("%s (MC), %s (DNM)", mcRaw, dnmRaw)
509-
510-
// Pad all fields using raw values
510+
511511
repoName := truncate(repoStat.RepoName, repoCol)
512512
combined := fmt.Sprintf("%*d", colWidths[1], repoStat.CombinedCount)
513-
skipped := fmt.Sprintf("%-*s", colWidths[2], skippedRaw)
514-
statusPadded := fmt.Sprintf("%-*s", colWidths[3], status)
515-
516-
// Now colorize only the numbers and status
517-
mcColored := colorize(mcRaw, mcColor)
518-
dnmColored := colorize(dnmRaw, dnmColor)
519-
skippedColored := skippedRaw
520-
skippedColored = strings.Replace(skippedColored, mcRaw, mcColored, 1)
521-
skippedColored = strings.Replace(skippedColored, dnmRaw, dnmColored, 1)
513+
// Pad skippedRaw to colWidths[2] before coloring
514+
skippedPadded := fmt.Sprintf("%-*s", colWidths[2], skippedRaw)
515+
// Colorize only the numbers in the padded string
516+
mcIdx := strings.Index(skippedPadded, mcRaw)
517+
dnmIdx := strings.Index(skippedPadded, dnmRaw)
518+
skippedColored := skippedPadded
519+
if mcIdx != -1 {
520+
skippedColored = skippedColored[:mcIdx] + colorize(mcRaw, mcColor) + skippedColored[mcIdx+len(mcRaw):]
521+
}
522+
if dnmIdx != -1 {
523+
dnmIdx = strings.Index(skippedColored, dnmRaw) // recalc in case mcRaw and dnmRaw overlap
524+
skippedColored = skippedColored[:dnmIdx] + colorize(dnmRaw, dnmColor) + skippedColored[dnmIdx+len(dnmRaw):]
525+
}
522526
statusColored := colorize(status, statusColor)
523-
statusColored = fmt.Sprintf("%-*s", colWidths[3]+len(statusColored)-len(status), statusColored) // pad after coloring
524-
527+
statusColored = fmt.Sprintf("%-*s", colWidths[3]+len(statusColored)-len(status), statusColored)
528+
525529
fmt.Printf(
526530
"│ %-*s │ %s │ %s │ %s │\n",
527531
repoCol, repoName,

0 commit comments

Comments
 (0)