SectionMarker returns a marker that may be used to denote sections. For example, SectionMarker("abc", '-', 21) would return: -------- abc --------
(centeredText string, fillerCharacter rune, totalLength int)
| 25 | // |
| 26 | // -------- abc -------- |
| 27 | func SectionMarker(centeredText string, fillerCharacter rune, totalLength int) string { |
| 28 | fillerStr := string(fillerCharacter) |
| 29 | remainingLength := totalLength - (len(centeredText) + 2) |
| 30 | if remainingLength <= 0 { |
| 31 | return fmt.Sprintf(" %s ", centeredText) |
| 32 | } |
| 33 | left := remainingLength / 2 |
| 34 | right := remainingLength - left // Integer division doesn't do fractions, so this will handle odd counts |
| 35 | return fmt.Sprintf("%s %s %s", |
| 36 | strings.Repeat(fillerStr, left), centeredText, strings.Repeat(fillerStr, right)) |
| 37 | } |
| 38 | |
| 39 | // PrintSectionMarker is a convenience function that prints the result of SectionMarker with a newline appended. |
| 40 | func PrintSectionMarker(centeredText string, fillerCharacter rune, totalLength int) { |
no test coverage detected