package door import ( "unicode" ) type Line struct { Text string DefaultColor string RenderF func(string) string UpdateF func() string } func (l *Line) Update() bool { if l.UpdateF == nil { return false } NewText := l.UpdateF() if NewText != l.Text { l.Text = NewText return true } return false } func (l *Line) Output() string { if l.RenderF == nil { return l.DefaultColor + l.Text } else { return l.RenderF(l.Text) } } // Sample RenderF function // Upcase is BOLD Blue, everything else is Yellow func RenderBlueYellow(text string) string { var output string var lastColor string blue := ColorText("BOLD BLUE") yellow := ColorText("BOLD YELLOW") for _, letter := range text { if unicode.IsUpper(letter) { if lastColor != blue { lastColor = blue output += blue } output += string(letter) } else { if lastColor != yellow { lastColor = yellow output += yellow } output += string(letter) } } return output }