Fixing edge case with terminals that dont support colors

This commit is contained in:
Michael Lazar
2017-12-07 21:58:12 -05:00
parent b69ee70366
commit 865040acf9
2 changed files with 7 additions and 6 deletions

View File

@@ -878,25 +878,26 @@ class Terminal(object):
""" """
terminal_colors = curses.COLORS if curses.has_colors() else 0 terminal_colors = curses.COLORS if curses.has_colors() else 0
default_theme = Theme(use_color=bool(terminal_colors))
if theme is None: if theme is None:
theme = Theme(use_color=bool(terminal_colors)) theme = default_theme
elif theme.required_color_pairs > curses.COLOR_PAIRS: elif theme.required_color_pairs > curses.COLOR_PAIRS:
_logger.warning( _logger.warning(
'Theme %s requires %s color pairs, but TERM %s only ' 'Theme `%s` requires %s color pairs, but $TERM=%s only '
'supports %s color pairs, switching to default theme', 'supports %s color pairs, switching to default theme',
theme.name, theme.required_color_pairs, self._term, theme.name, theme.required_color_pairs, self._term,
curses.COLOR_PAIRS) curses.COLOR_PAIRS)
theme = Theme() theme = default_theme
elif theme.required_colors > terminal_colors: elif theme.required_colors > terminal_colors:
_logger.warning( _logger.warning(
'Theme %s requires %s colors, but TERM %s only ' 'Theme `%s` requires %s colors, but $TERM=%s only '
'supports %s colors, switching to default theme', 'supports %s colors, switching to default theme',
theme.name, theme.required_colors, self._term, theme.name, theme.required_colors, self._term,
curses.COLORS) curses.COLORS)
theme = Theme() theme = default_theme
theme.bind_curses() theme.bind_curses()
self.theme = theme self.theme = theme

View File

@@ -2,11 +2,11 @@ import os
import codecs import codecs
import curses import curses
import logging import logging
import configparser
from collections import OrderedDict from collections import OrderedDict
from contextlib import contextmanager from contextlib import contextmanager
import six import six
from six.moves import configparser
from .config import THEMES, DEFAULT_THEMES from .config import THEMES, DEFAULT_THEMES
from .exceptions import ConfigError from .exceptions import ConfigError