Open kokizzu opened 9 years ago
I'll take a look atwhat this will entail, but I suspect it will require a beefy terminal library and I'd prefer to not rely on anything not in the stdlib.
@davecgh I was looking into this earlier, and although it may not work on all terminals, using the ASCII escape codes works just fine for in iTerm, which I assume means that it should work in Unix based terminals. I haven't tested it in any other terminals though, so I can't be sure how widely compatible it is.
To use it, you basically just insert the relevant escape sequence into the string where you want it to change colour, and from that point on it's that colour until you change it to something else. Here's a quick example to illustrate what I mean.
package main
import (
"fmt"
"strings"
"github.com/davecgh/go-spew/spew"
)
type Person struct {
Name string
Age int
Children *[]Person
SpouseName string
}
func main() {
cs := spew.NewDefaultConfig()
cs.Indent = " "
t := Person{
Name: "John",
Age: 37,
Children: &[]Person{
Person{
Name: "Amy",
Age: 1,
},
},
SpouseName: "Tetyana",
}
s := cs.Sdump(t)
i := strings.Index(s, "Amy")
lenAmy := len("Amy")
red := "\x1b[31m"
def := "\x1b[39;49m"
ns := s[:i] + red + s[i:i+lenAmy] + def + s[i+lenAmy:]
fmt.Println(ns)
}
And the output then looks like:
Sorry to resurrect this old issue, it would be great to see a little more colour in the terminal 👍
Sorry to resurrect this old issue, it would be great to see a little more colour in the terminal 👍
Yes, I Agree
It would be nice if this library as similar as possible to Ruby's
awesome_print
that gives colorized output