From 9520394149dc18bf83e3c11877d50f3b2cd27dff Mon Sep 17 00:00:00 2001 From: Erik Rose Date: Fri, 30 Aug 2013 16:29:51 -0400 Subject: 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. --- blessings/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'blessings') 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 -- cgit v1.2.1