summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blessings/__init__.py18
1 files changed, 7 insertions, 11 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index 7df617d..9d37889 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -294,7 +294,8 @@ class Terminal(object):
:arg num: The number, 0-15, of the color
"""
- return ParametrizingString(self._foreground_color, self.normal)
+ return (ParametrizingString(self._foreground_color, self.normal)
+ if self.does_styling else NullCallableString())
@property
def on_color(self):
@@ -303,7 +304,8 @@ class Terminal(object):
See ``color()``.
"""
- return ParametrizingString(self._background_color, self.normal)
+ return (ParametrizingString(self._background_color, self.normal)
+ if self.does_styling else NullCallableString())
@property
def number_of_colors(self):
@@ -325,11 +327,11 @@ class Terminal(object):
# don't name it after the underlying capability, because we deviate
# slightly from its behavior, and we might someday wish to give direct
# access to it.
- colors = tigetnum('colors') # Returns -1 if no color support, -2 if no
- # such cap.
+ # Returns -1 if no color support, -2 if no such capability.
+ colors = self.does_styling and tigetnum('colors') or -1
# self.__dict__['colors'] = ret # Cache it. It's not changing.
# (Doesn't work.)
- return colors if colors >= 0 else 0
+ return max(0, colors)
def _resolve_formatter(self, attr):
"""Resolve a sugary or plain capability name, color, or compound
@@ -439,12 +441,6 @@ class ParametrizingString(unicode):
parametrized = tparm(self.encode('utf-8'), *args).decode('utf-8')
return (parametrized if self._normal is None else
FormattingString(parametrized, self._normal))
- except curses.error:
- # Catch "must call (at least) setupterm() first" errors, as when
- # running simply `nosetests` (without progressive) on nose-
- # progressive. Perhaps the terminal has gone away between calling
- # tigetstr and calling tparm.
- return u''
except TypeError:
# If the first non-int (i.e. incorrect) arg was a string, suggest
# something intelligent: