Skip to content
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

Open
kokizzu opened this issue Dec 1, 2014 · 5 comments
Open

Feature Request: add colorized output/option on console #20

kokizzu opened this issue Dec 1, 2014 · 5 comments

Comments

@kokizzu
Copy link

kokizzu commented Dec 1, 2014

It would be nice if this library as similar as possible to Ruby's awesome_print that gives colorized output
image

@davecgh
Copy link
Owner

davecgh commented Dec 16, 2014

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.

@johngb
Copy link

johngb commented Dec 29, 2014

@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:
screenshot 2014-12-29 13 18 46

@pjebs
Copy link

pjebs commented Jun 28, 2015

it's actually quite easy to do.

See generally:

https://github.com/op/go-logging

@adamlc
Copy link

adamlc commented Jul 10, 2018

Sorry to resurrect this old issue, it would be great to see a little more colour in the terminal 👍

@awkj
Copy link

awkj commented Jan 11, 2019

Sorry to resurrect this old issue, it would be great to see a little more colour in the terminal 👍

Yes, I Agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants