diff options
author | Erik Rose <erik@mozilla.com> | 2013-08-30 16:29:51 -0400 |
---|---|---|
committer | Erik Rose <erik@mozilla.com> | 2013-08-30 16:29:51 -0400 |
commit | 9520394149dc18bf83e3c11877d50f3b2cd27dff (patch) | |
tree | 59a303a6ba624943461b049d6cbd2ae58b79a874 /blessings | |
parent | e899c7241d82dd350ed90b3d90706b40139a9171 (diff) | |
download | blessings-9520394149dc18bf83e3c11877d50f3b2cd27dff.tar.gz |
Make does_styling attr public. Bump version to 1.6.
This is more often what's intended when is_a_tty is examined. While a caller could keep track of what he's passed to the Terminal constructor, it is often more convenient to have the info available directly on the instance, which we're already passing around everywhere.
Diffstat (limited to 'blessings')
-rw-r--r-- | blessings/__init__.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py index 725602e..e13b70e 100644 --- a/blessings/__init__.py +++ b/blessings/__init__.py @@ -40,9 +40,13 @@ class Terminal(object): around with the terminal; it's almost always needed when the terminal is and saves sticking lots of extra args on client functions in practice. + ``does_styling`` + Whether this ``Terminal`` attempts to emit capabilities. This is + influenced by ``is_a_tty`` and by the ``force_styling`` arg to the + constructor. You can examine this value to decide whether to draw + progress bars or other frippery. ``is_a_tty`` - Whether ``stream`` appears to be a terminal. You can examine this value - to decide whether to draw progress bars or other frippery. + Whether ``stream`` appears to be a terminal. """ def __init__(self, kind=None, stream=None, force_styling=False): @@ -83,8 +87,8 @@ class Terminal(object): stream_descriptor = None self.is_a_tty = stream_descriptor is not None and isatty(stream_descriptor) - self._does_styling = ((self.is_a_tty or force_styling) and - force_styling is not None) + self.does_styling = ((self.is_a_tty or force_styling) and + force_styling is not None) # The desciptor to direct terminal initialization sequences to. # sys.__stdout__ seems to always have a descriptor of 1, even if output @@ -92,7 +96,7 @@ class Terminal(object): self._init_descriptor = (sys.__stdout__.fileno() if stream_descriptor is None else stream_descriptor) - if self._does_styling: + if self.does_styling: # Make things like tigetstr() work. Explicit args make setupterm() # work even when -s is passed to nosetests. Lean toward sending # init sequences to the stream if it has a file descriptor, and @@ -168,7 +172,7 @@ class Terminal(object): Return values are always Unicode. """ - resolution = self._resolve_formatter(attr) if self._does_styling else NullCallableString() + resolution = self._resolve_formatter(attr) if self.does_styling else NullCallableString() setattr(self, attr, resolution) # Cache capability codes. return resolution |