Add TTY detection#47
Conversation
Now, 'pPrint' and dark/light background variations will only color the output if they are writing to a TTY. Also, new functions, the 'pPrintForceColor' family, have been added, that skip this check, like 'pPrint' used to do.
| -- Helpers | ||
| ------------------------------------------ | ||
|
|
||
| pStringTTYIO :: String -> IO Text |
There was a problem hiding this comment.
I don't like it but it works, and I couldn't find a better solution quickly, and I wanted to push something out before going to sleep lol
There was a problem hiding this comment.
This seems reasonable. I changed it to check stderr instead of stdout, since it looks like the trace functions output to stderr. But other than that this looks good.
| pStringTTYIO v = checkTTY defaultOutputOptionsDarkBg <&> \o -> pStringOpt o v | ||
|
|
||
| pStringTTY :: String -> Text | ||
| pStringTTY = unsafePerformIO . pStringTTYIO |
There was a problem hiding this comment.
As I mentioned in the commit message, unsafePerformIO seems unavoidable.
There was a problem hiding this comment.
It looks like the trace functions are using unsafePerformIO internally, so this seems reasonable:
http://hackage.haskell.org/package/base-4.12.0.0/docs/src/Debug.Trace.html#trace
Sadly, unsafePerformIO seems unavoidable.
…ns that take a Handle.
…her to print in color.
|
@metiulekm Thanks for this PR! I cleaned this up a little bit in the last couple of commits. Could you do one final review of this? If you sign off on it, I'll merge it in and make a new release. |
|
I've removed the |
|
Thanks! Released on Hackage as pretty-simple-3.0.0.0: |
Closes #46.
Seems to work but please recheck.