summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Rose <erik@mozilla.com>2011-11-29 11:26:04 -0800
committerErik Rose <erik@mozilla.com>2011-11-29 11:26:04 -0800
commitacb4cc836176e18517ed26ea3a03ece7ee3e6b9a (patch)
tree137373b6b573d824b311dcd7f3078852b78141a9
parentcd8fbd9d04db72aa74c33647730c142eda92286e (diff)
downloadblessings-acb4cc836176e18517ed26ea3a03ece7ee3e6b9a.tar.gz
Invert _is_null to save a few lines.
-rw-r--r--blessings/__init__.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index 500982f..1fde89f 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -18,7 +18,8 @@ from termios import TIOCGWINSZ
if ('3', '0', '0') <= python_version_tuple() < ('3', '2', '2+'): # Good till 3.2.10
# Python 3.x < 3.2.3 has a bug in which tparm() erroneously takes a string.
- raise ImportError('Blessings needs Python 3.2.3 or greater for Python 3 support due to http://bugs.python.org/issue10570.')
+ raise ImportError('Blessings needs Python 3.2.3 or greater for Python 3 '
+ 'support due to http://bugs.python.org/issue10570.')
__all__ = ['Terminal']
@@ -79,7 +80,8 @@ class Terminal(object):
stream_descriptor = None
self.is_a_tty = stream_descriptor is not None and isatty(stream_descriptor)
- if self.is_a_tty or force_styling:
+ self._does_styling = self.is_a_tty or force_styling
+ if self._does_styling:
# The desciptor to direct terminal initialization sequences to.
# sys.__stdout__ seems to always have a descriptor of 1, even if
# output is redirected.
@@ -93,9 +95,6 @@ class Terminal(object):
# somewhere.
setupterm(kind or environ.get('TERM', 'unknown'),
init_descriptor)
- self._is_null = False
- else:
- self._is_null = True
self.stream = stream
@@ -154,7 +153,7 @@ class Terminal(object):
Return values are always Unicode.
"""
- resolution = NullCallableString() if self._is_null else self._resolve_formatter(attr)
+ resolution = self._resolve_formatter(attr) if self._does_styling else NullCallableString()
setattr(self, attr, resolution) # Cache capability codes.
return resolution