File: longest_line.go

package info (click to toggle)
golang-github-pterm-pterm 0.12.79-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,640 kB
  • sloc: makefile: 4
file content (21 lines) | stat: -rw-r--r-- 452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package internal

import (
	"strings"

	"github.com/gookit/color"
	"github.com/mattn/go-runewidth"
)

// ReturnLongestLine returns the longest line with a given separator
func ReturnLongestLine(text, sep string) string {
	lines := strings.Split(text, sep)
	var longest string
	for _, line := range lines {
		if runewidth.StringWidth(color.ClearCode(line)) > runewidth.StringWidth(color.ClearCode(longest)) {
			longest = line
		}
	}

	return longest
}