I am trying to test some functions that print ANSI escape codes. e.g.
// Print a line in a color
func PrintlnColor(color string, a ...interface{}) {
fmt.Print("\x1b[31m")
fmt.Print(a...)
fmt.Println("\x1b[0m")
}
I tried using Examples to do it, but they don't seem to like escape codes.
Is there any way to test what is written to stdout?
Using
fmt.Fprintto print toio.Writerlets you control where the output is written.Go play