k0kubun/pp

disable colors when not output is not a tty

mtourne opened this issue · 6 comments

Colors are great and make the output very readable, however it's a pain when trying to output to a file

go-isatty[1] seems like it would be a good addition to this project to solve this

[1] https://github.com/mattn/go-isatty

Would be nice to have option to disable colors.

Obviously nicer to have a function that does this, but can't you just do something like this?

	pp.SetColorScheme(pp.ColorScheme{
		Bool:            pp.NoColor,
		Integer:         pp.NoColor,
		Float:           pp.NoColor,
		String:          pp.NoColor,
		StringQuotation: pp.NoColor,
		EscapedChar:     pp.NoColor,
		FieldName:       pp.NoColor,
		PointerAdress:   pp.NoColor,
		Nil:             pp.NoColor,
		Time:            pp.NoColor,
		StructName:      pp.NoColor,
		ObjectLength:    pp.NoColor,
	})

Right, thanks for your comment!

@k0kubun Why is ColoringEnabled placed as package variable instead of PrettyPrinter member? I need to disable coloring of individual PrettyPrinter. (Is this question out of scoping of this issue, I wonder. Sorry.)

PrettyPrinter was added very recently 45cd653, ColoringEnabled has been a very traditional variable 82c68cb and therefore I need to maintain its backward compatibility.

But I see what you mean. Could you try PrettyPrinter.SetColoringEnabled() in #37? If that's what you want, I'll merge it.