-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in the commit message, unsafePerformIO
seems unavoidable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.