mattn / go-colorable

http://godoc.org/github.com/mattn/go-colorable
MIT License
766 stars 93 forks source link

Allow passing `io.Writer` instead of `*os.File` to the `NewColorable` func #65

Open cardil opened 1 year ago

cardil commented 1 year ago

The NewColorable func forces users to pass a *os.File. It should accept io.Writer instead. The func could verify if a given writer is a real TTY, and act accordingly.

dolmen commented 1 year ago

Why do you need this?

Why is the following function not enough?

func setColorable(w io.Writer) io.Writer {
    if f, isFile := w.(*os.File); isFile {
        return colorable.NewColorable(f)
    }
    return w
}