keewis / blackdoc

run black on documentation code snippets
https://blackdoc.readthedocs.io
MIT License
47 stars 4 forks source link

color in redirected output #66

Closed keewis closed 3 years ago

keewis commented 3 years ago

I just noticed that unlike black the colored output is not stripped in redirected output, which might look a bit strange if the pager does not interpret the color codes. The typical way to fix this is by checking if sys.stdout (or sys.stderr, if we're writing to that) is connected to a TTY using os.isatty().