From 6679ec8c7fc04bf4d31504c4f9d6f2b9006725d3 Mon Sep 17 00:00:00 2001 From: Nicolas Peugnet Date: Sun, 30 Jun 2024 18:31:51 +0200 Subject: [PATCH] fix: verbose analyse output improperly trimmed (#3785) Due to the `second` column value ending with `colors.Reset` for top-level entries, it was improperly trimmed, thus resulting in a larger space after it (and a smaler line in verbose mode). --- pkg/api/api_impl.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/api/api_impl.go b/pkg/api/api_impl.go index 291dcd20e51..e07e901bae5 100644 --- a/pkg/api/api_impl.go +++ b/pkg/api/api_impl.go @@ -2350,11 +2350,11 @@ func analyzeMetafileImpl(metafile string, opts AnalyzeMetafileOptions) string { third := "100.0%" table = append(table, tableEntry{ - first: fmt.Sprintf("%s%s%s", colors.Bold, entry.name, colors.Reset), + first: entry.name, firstLen: utf8.RuneCountInString(entry.name), - second: fmt.Sprintf("%s%s%s", colors.Bold, second, colors.Reset), + second: second, secondLen: len(second), - third: fmt.Sprintf("%s%s%s", colors.Bold, third, colors.Reset), + third: third, thirdLen: len(third), isTopLevel: true, }) @@ -2431,8 +2431,10 @@ func analyzeMetafileImpl(metafile string, opts AnalyzeMetafileOptions) string { // Render the columns now that we know the widths for _, entry := range table { prefix := "\n" + color := colors.Bold if !entry.isTopLevel { prefix = "" + color = "" } // Import paths don't have second and third columns @@ -2454,17 +2456,23 @@ func analyzeMetafileImpl(metafile string, opts AnalyzeMetafileOptions) string { extraSpace = 1 } - sb.WriteString(fmt.Sprintf("%s %s %s%s%s %s %s%s%s %s\n", + sb.WriteString(fmt.Sprintf("%s %s%s%s %s%s%s %s%s%s %s%s%s %s%s%s\n", prefix, + color, entry.first, + colors.Reset, colors.Dim, strings.Repeat(lineChar, extraSpace+maxFirstLen-entry.firstLen+maxSecondLen-entry.secondLen), colors.Reset, + color, secondTrimmed, + colors.Reset, colors.Dim, strings.Repeat(lineChar, extraSpace+maxThirdLen-entry.thirdLen+len(second)-len(secondTrimmed)), colors.Reset, + color, entry.third, + colors.Reset, )) }