diff --git a/size.go b/size.go index 439a5cb8..10a1c9f3 100644 --- a/size.go +++ b/size.go @@ -23,6 +23,20 @@ func Width(str string) (width int) { return width } +// Widest returns the string with the widest cell with in a slice of strings. +// ANSI sequences are ignored. If a string contains a newline it will be +// treated as two separate strings, returning only the widest. +func Widest(strs []string) (width int) { + for _, str := range strs { + w := Width(str) + if w > width { + width = w + } + } + + return width +} + // Height returns height of a string in cells. This is done simply by // counting \n characters. If your strings use \r\n for newlines you should // convert them to \n first, or simply write a separate function for measuring