Skip to content

Commit

Permalink
Restore earlier trimTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
godrei committed Dec 9, 2022
1 parent 4b88264 commit 8796da7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 15 additions & 1 deletion bitrise/print.go
Expand Up @@ -26,7 +26,21 @@ const (

func trimTitle(title string, titleSuffix string, titleBoxWidth int) string {
titleWithSuffix := combineTitleAndSuffix(title, titleSuffix)
return log.WidthConstrainedString(titleWithSuffix, titleBoxWidth)

titleWithSuffixLength := len(titleWithSuffix)
if titleWithSuffixLength > titleBoxWidth {
diff := titleWithSuffixLength - titleBoxWidth

// TODO: if len(titleWithSuffix) > titleBoxWidth because of a long suffix,
// might we trim too much from the title
if len(title) > 0 {
title = stringutil.MaxFirstCharsWithDots(title, len(title)-diff)
} else if len(titleSuffix) > 0 {
titleSuffix = stringutil.MaxFirstCharsWithDots(titleSuffix, len(titleSuffix)-diff)
}
}

return combineTitleAndSuffix(title, titleSuffix)
}

func combineTitleAndSuffix(title, suffix string) string {
Expand Down
8 changes: 4 additions & 4 deletions log/event_print.go
Expand Up @@ -64,10 +64,10 @@ func getHeaderLine(content string) string {
}

func widthConstrainedStringWithBorder(content string, width int) string {
return fmt.Sprintf("| %s |", WidthConstrainedString(content, width))
return fmt.Sprintf("| %s |", widthConstrainedString(content, width))
}

func WidthConstrainedString(content string, width int) string {
func widthConstrainedString(content string, width int) string {
widthDiff := len(content) - width

if widthDiff < 0 {
Expand Down Expand Up @@ -211,10 +211,10 @@ func getFooterTitle(level corelog.Level, title, reason string, deprecated bool,

// Deduct the deprecated prefix length and the space between them to only shorten the title
actualWidth = actualWidth - len(deprecatedPrefix) - 1
widthConstrainedTitle := WidthConstrainedString(title, actualWidth)
widthConstrainedTitle := widthConstrainedString(title, actualWidth)
title = fmt.Sprintf("%s %s", corelog.AddColor(corelog.ErrorLevel, deprecatedPrefix), corelog.AddColor(level, widthConstrainedTitle))
} else {
title = WidthConstrainedString(title, actualWidth)
title = widthConstrainedString(title, actualWidth)
title = corelog.AddColor(level, title)
}

Expand Down

0 comments on commit 8796da7

Please sign in to comment.