segmentio / golines

A golang formatter that fixes long lines
MIT License
907 stars 56 forks source link

Don't add colors unless output goes to a terminal #50

Closed telemachus closed 2 years ago

telemachus commented 2 years ago

The embedded python script currently adds color codes even if the user redirects output to a file (e.g., golines --dry-run file.go > diff.txt).

This updated version uses isatty to prevent that.

telemachus commented 2 years ago

While I'm here, I have a question. Would you consider a PR that implements diffing in Go using a library rather than with the Python script? (E.g., https://github.com/pmezard/go-difflib.)

I completely understand if you feel like golines works and why mess with it, but I'm happy to work on it if you are open to the change. Either way, thanks for the tool.

yolken-segment commented 2 years ago

@telemachus yes, that would be great. I actually used that library in a separate project that needed diff outputs (https://github.com/segmentio/kubeapply/blob/master/pkg/cluster/diff/diff.go#L177), and it worked well, but I never got around to updating things here.