-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: add colorized output/option on console #20
Comments
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)
} |
it's actually quite easy to do. See generally: |
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 outputThe text was updated successfully, but these errors were encountered: