File: max_text_width.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 (20 lines) | stat: -rw-r--r-- 447 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package internal

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

// GetStringMaxWidth returns the maximum width of a string with multiple lines.
func GetStringMaxWidth(s string) int {
	var max int
	ss := strings.Split(s, "\n")
	for _, s2 := range ss {
		s2WithoutColor := color.ClearCode(s2)
		if runewidth.StringWidth(s2WithoutColor) > max {
			max = runewidth.StringWidth(s2WithoutColor)
		}
	}
	return max
}