cdepillabout / pretty-simple

pretty-printer for Haskell data types that have a Show instance
https://hackage.haskell.org/package/pretty-simple
BSD 3-Clause "New" or "Revised" License
243 stars 29 forks source link

pPretty detected tty for whether to enable color or not #46

Closed juhp closed 5 years ago

juhp commented 5 years ago

For example if one outputs to a pipe, file or Emacs shell-command etc, then the ANSI color control characters are visible , so it would be better to detect whether one is using a TTY terminal or not and depending on that decide whether to enable color or not in the default output.

One can do this by using say https://hackage.haskell.org/package/base-4.12.0.0/docs/System-IO.html#v:hIsTerminalDevice

cdepillabout commented 5 years ago

This sounds like a good idea to me. I'd be willing to accept a PR implementing this.

It would also be nice to make it an option so the end user could configure this.

This shouldn't be too hard, so I'll mark it beginner friendly.

metiulekm commented 5 years ago

If nobody else feels like doing so, I will try doing this in the evening (GMT+2).

We should probably add functions that always print colored output, even outside TTYs, and also the tracing functions should somehow do the detection too, right?