colorama icon indicating copy to clipboard operation
colorama copied to clipboard

How to enable colorama in Gitlab tty (and other online services that seem to support colors in terminal)

Open gsemet opened this issue 5 years ago • 2 comments

Hi. I have been using colorama since quite a while, and I see it automatically disable itself when executed outside of a terminal, to avoid unwanted ascii string everywhere on the screen.

But since some CI such as Gitlab or Travis does support colors in their output, I wonder how colorama would be made compatible, and so identify "hum, this is not a tty on a terminal that support colors, but i recognise such or such environment and so I keep the color on". Maybe by a environment variable?

gsemet avatar Mar 06 '19 08:03 gsemet

I would also like an environment variable to force Colorama to output color escape sequences, for the same reason.

jan11011977 avatar Apr 11 '19 09:04 jan11011977

Seems like since 2057f03 (edit only moved there, existed before already) you could use a workaround of setting PYCHARM_HOSTED: https://github.com/tartley/colorama/blob/b760506a61f3d20e80e33f1e16cd6fc67a2d7708/colorama/ansitowin32.py#L45

There's also the method of using "strip=True, convert=True" directly with the AnsiToWin32 object.

I agree however that COLORAMA_FORCE_COLOR and possibly FORCE_COLOR as a fallback should be honored (instead of only "PYCHARM_HOSTED").

I've tested / looked into this for Windows builds on Travis. With regard to that it looks like the "winterm" check (to setup the dict of conversions) is not True already likely (https://github.com/tartley/colorama/blob/b760506a61f3d20e80e33f1e16cd6fc67a2d7708/colorama/ansitowin32.py#L11-L13).

See also https://github.com/tartley/colorama/issues/165.

blueyed avatar Aug 16 '19 22:08 blueyed