Browse files

Provide a decent way to say "don't style". Closes #18.

  • Loading branch information...
1 parent d04c999 commit cc42aad389c4022c5b7a1cfd72c4173d1ee23e62 @erikrose committed Jun 16, 2012
Showing with 15 additions and 3 deletions.
  1. +4 −2 README.rst
  2. +5 −1 blessings/__init__.py
  3. +6 −0 blessings/tests.py
View
6 README.rst
@@ -343,7 +343,7 @@ into this behavior, but Blessings makes it optional. If you want to do the
state-restoration thing, use these capabilities:
``enter_fullscreen``
- Switch to the terminal mode where full-screen output is sanctioned. Call
+ Switch to the terminal mode where full-screen output is sanctioned. Print
this before you do any output.
``exit_fullscreen``
Switch back to normal mode, restoring the exact state from before
@@ -361,7 +361,7 @@ There's also a context manager you can use as a shortcut::
# Print some stuff.
Besides brevity, another advantage is that it switches back to normal mode even
-if an exception is raised in the with block.
+if an exception is raised in the ``with`` block.
Pipe Savvy
----------
@@ -434,6 +434,8 @@ Version History
* Add syntactic sugar and documentation for ``enter_fullscreen`` and
``exit_fullscreen``.
* Add context managers ``fullscreen()`` and ``hidden_cursor()``.
+ * Now you can force a ``Terminal`` never to emit styles by passing
+ ``force_styling=None``.
1.4
* Add syntactic sugar for cursor visibility control and single-space-movement
View
6 blessings/__init__.py
@@ -69,6 +69,9 @@ def __init__(self, kind=None, stream=None, force_styling=False):
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 @@ def __init__(self, kind=None, stream=None, force_styling=False):
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
View
6 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, '')

0 comments on commit cc42aad

Please sign in to comment.