diff options
author | Erik Rose <grinch@grinchcentral.com> | 2012-06-16 16:58:05 -0700 |
---|---|---|
committer | Erik Rose <grinch@grinchcentral.com> | 2012-06-16 16:58:05 -0700 |
commit | cc42aad389c4022c5b7a1cfd72c4173d1ee23e62 (patch) | |
tree | 2a82e14bc74673fb0a4fe346651860506d3135b3 /blessings | |
parent | d04c99970194449ca2db0592243f7ea189f5a098 (diff) | |
download | blessings-cc42aad389c4022c5b7a1cfd72c4173d1ee23e62.tar.gz |
Provide a decent way to say "don't style". Closes #18.
Diffstat (limited to 'blessings')
-rw-r--r-- | blessings/__init__.py | 6 | ||||
-rw-r--r-- | blessings/tests.py | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py index 0126ea2..68212c2 100644 --- a/blessings/__init__.py +++ b/blessings/__init__.py @@ -69,6 +69,9 @@ class Terminal(object): somewhere, and stdout is probably where the output is ultimately headed. If not, stderr is probably bound to the same terminal.) + If you want to force styling to not happen, pass + ``force_styling=None``. + """ if stream is None: stream = sys.__stdout__ @@ -80,7 +83,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 + 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 diff --git a/blessings/tests.py b/blessings/tests.py index 817e766..a885c65 100644 --- a/blessings/tests.py +++ b/blessings/tests.py @@ -248,3 +248,9 @@ def test_init_descriptor_always_initted(): """We should be able to get a height and width even on no-tty Terminals.""" t = Terminal(stream=StringIO()) eq_(type(t.height), int) + + +def test_force_styling_none(): + """If ``force_styling=None`` is passed to the constructor, don't ever do styling.""" + t = TestTerminal(force_styling=None) + eq_(t.save, '') |