Clean up code

This commit is contained in:
Tulir Asokan
2018-05-22 17:23:54 +03:00
parent 09703c6b9c
commit cce79ab7d8
6 changed files with 204 additions and 206 deletions

View File

@ -67,19 +67,22 @@ func (str TString) Append(data string) TString {
}
func (str TString) AppendColor(data string, color tcell.Color) TString {
newStr := make(TString, len(str)+len(data))
copy(newStr, str)
for i, char := range data {
newStr[i+len(str)] = NewColorCell(char, color)
}
return newStr
return str.AppendCustom(data, func(r rune) Cell {
return NewColorCell(r, color)
})
}
func (str TString) AppendStyle(data string, style tcell.Style) TString {
return str.AppendCustom(data, func(r rune) Cell {
return NewStyleCell(r, style)
})
}
func (str TString) AppendCustom(data string, cellCreator func(rune) Cell) TString {
newStr := make(TString, len(str)+len(data))
copy(newStr, str)
for i, char := range data {
newStr[i+len(str)] = NewStyleCell(char, style)
newStr[i+len(str)] = cellCreator(char)
}
return newStr
}