Qix-/better-exceptions

Color support for non-xterm terminals

philer opened this issue · 6 comments

The nocolor check is a bit too strict:

NOCOLOR = not os.isatty(2) or os.name == 'nt' or os.getenv('TERM', '')[:5] != 'xterm'

There are a lot of terminals that don't set their TERM env to xterm but support colors (e.g. TERM=urxvt-unicode-256color), including the TTYs on many systems. I'd suggest omitting the TERM check or limiting it to a few common excludes.


PS: If anyone else uses a terminal where color support is blocked (like urxvt) you can work around it by explicitly overwriting the NOCOLOR variable:

import better_exceptions
better_exceptions.NOCOLOR = False
Qix- commented

Yep, I'll do a proper fix for this sometime today.

Qix- commented

Does the branch fix-colors work for you? :)

Qix- commented

@philer could you test the latest on fix-colors?

If you're not getting any colors, make sure curses/ncurses is installed. This isn't required on Windows as it falls back to Colorama.

There seems to be a bug with Colorama on Windows under Python 3. Can track the progression of that bug in tartley/colorama#125. Python 2 is confirmed to work.

Mac:

$ brew install homebrew/dupes/ncurses

Ubuntu:

$ sudo apt-get install libncurses5-dev
Qix- commented

I tested personally in Windows. Other than the above bug, this is working for all terminals (not just xterm).

Any problems with the new detection method should go into a new ticket :)

Released as 0.1.4.

Just some quick notes: In 0.1.4, NOCOLOR was replaced by SUPPORTS_COLOR.
@philer's method then transforms to

import better_exceptions
better_exceptions.SUPPORTS_COLOR = True

Alternatively, one can set the environment variable FORCE_COLOR to 1:

export FORCE_COLOR=1

@Qix- Yeah that works. Thanks for the fast fix!