diff --git a/httpie/context.py b/httpie/context.py index 13763475..ed7ff13a 100644 --- a/httpie/context.py +++ b/httpie/context.py @@ -1,4 +1,3 @@ -import os import sys from requests.compat import is_windows @@ -18,7 +17,6 @@ class Environment(object): """ is_windows = is_windows config_dir = DEFAULT_CONFIG_DIR - colors = 256 if '256color' in os.environ.get('TERM', '') else 88 stdin = sys.stdin stdin_isatty = stdin.isatty() stdin_encoding = None @@ -27,13 +25,24 @@ class Environment(object): stdout_encoding = None stderr = sys.stderr stderr_isatty = stderr.isatty() - if is_windows: + if not is_windows: + import curses + curses.setupterm() + colors = curses.tigetnum('colors') + del curses + else: + colors = 256 # noinspection PyUnresolvedReferences - from colorama.initialise import wrap_stream - stdout = wrap_stream(stdout, convert=None, strip=None, - autoreset=True, wrap=True) - stderr = wrap_stream(stderr, convert=None, strip=None, - autoreset=True, wrap=True) + import colorama.initialise + stdout = colorama.initialise.wrap_stream( + stdout, convert=None, strip=None, + autoreset=True, wrap=True + ) + stderr = colorama.initialise.wrap_stream( + stderr, convert=None, strip=None, + autoreset=True, wrap=True + ) + del colorama def __init__(self, **kwargs): """ @@ -51,6 +60,7 @@ class Environment(object): if self.stdout_encoding is None: actual_stdout = self.stdout if is_windows: + # noinspection PyUnresolvedReferences from colorama import AnsiToWin32 if isinstance(self.stdout, AnsiToWin32): actual_stdout = self.stdout.wrapped diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index bcec7ba1..d9276d6f 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -42,7 +42,7 @@ class ColorFormatter(FormatterPlugin): except ClassNotFound: style_class = Solarized256Style - if env.is_windows or env.colors == 256: + if env.colors == 256: fmt_class = Terminal256Formatter else: fmt_class = TerminalFormatter