|
@@ -197,7 +197,7 @@ func (r *Render) Append(color string, len int) {
|
|
|
|
|
|
// RenderBlueYellow - Uppercase is Bold Blue, everything else is Yellow.
|
|
// RenderBlueYellow - Uppercase is Bold Blue, everything else is Yellow.
|
|
// This is an example of using the door.Render routines.
|
|
// This is an example of using the door.Render routines.
|
|
-func RenderBlueYellow(text string) string {
|
|
|
|
|
|
+func RenderBlueYellowOld(text string) string {
|
|
var r Render = Render{Line: text}
|
|
var r Render = Render{Line: text}
|
|
|
|
|
|
var blue string = ColorText("BOLD BLUE")
|
|
var blue string = ColorText("BOLD BLUE")
|
|
@@ -212,3 +212,45 @@ func RenderBlueYellow(text string) string {
|
|
}
|
|
}
|
|
return r.Result
|
|
return r.Result
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+var RenderPool = sync.Pool{
|
|
|
|
+ New: func() any {
|
|
|
|
+ return new(strings.Builder)
|
|
|
|
+ },
|
|
|
|
+}
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+// Render is the old way of doing things...
|
|
|
|
+// Using strings.Builder ...
|
|
|
|
+
|
|
|
|
+func RenderBlueYellow(text string) string {
|
|
|
|
+ var output strings.Builder
|
|
|
|
+
|
|
|
|
+ // var output = RenderPool.Get().(*strings.Builder)
|
|
|
|
+ // output.Reset()
|
|
|
|
+
|
|
|
|
+ var blue string = ColorText("BOLD BLUE")
|
|
|
|
+ var yellow string = ColorText("BOLD YELLOW")
|
|
|
|
+ var last *string
|
|
|
|
+
|
|
|
|
+ for _, letter := range text {
|
|
|
|
+ if unicode.IsUpper(letter) {
|
|
|
|
+ if last != &blue {
|
|
|
|
+ output.WriteString(blue)
|
|
|
|
+ last = &blue
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if last != &yellow {
|
|
|
|
+ output.WriteString(yellow)
|
|
|
|
+ last = &yellow
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ output.WriteRune(letter)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // var result = output.String()
|
|
|
|
+ // RenderPool.Put(output)
|
|
|
|
+ // return result
|
|
|
|
+ return output.String()
|
|
|
|
+}
|