shell/colorstring.go

47 lines
815 B
Go
Raw Normal View History

2023-03-19 13:08:11 +01:00
package main
import (
"unicode/utf8"
"github.com/fatih/color"
)
type ColorString struct {
color string
raw string
}
func (s *ColorString) Append(str string, attrs ...color.Attribute) *ColorString {
s.color += color.New(attrs...).Sprint(str)
s.raw += str
return s
}
func (s *ColorString) AppendColorString(str ...*ColorString) *ColorString {
for _, o := range str {
s.color += o.color
s.raw += o.raw
}
return s
}
func (s *ColorString) Equals(other *ColorString) bool {
return s.color == other.color && s.raw == other.raw
}
func (s *ColorString) Len() int {
return utf8.RuneCountInString(s.raw)
}
func (s *ColorString) ColorLen() int {
return utf8.RuneCountInString(s.color)
}
func (s *ColorString) String() string {
return s.color
}
func (s *ColorString) Raw() string {
return s.raw
}