summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Rose <grinch@grinchcentral.com>2013-11-05 20:44:35 -0500
committerErik Rose <grinch@grinchcentral.com>2013-11-05 20:44:35 -0500
commitc3ca6a4e14867370593491abf5dc8ffe44fd6041 (patch)
tree3a03ab1e180f9450b019418025a5bae198abde40
parentf86d9dbb794bad383b7cfb79989954d3aa0bdfc2 (diff)
downloadblessings-c3ca6a4e14867370593491abf5dc8ffe44fd6041.tar.gz
Remove fallback to 24x80, and fix docstring formatting.
There are some advantages to falling back to 24x80: for example, the ability to easily render output based on height and width when being piped through `less`. However, that's a backward incompatible change--we explicitly documented the None return values in earlier versions--so I don't want to make it lightly. Reverting it for now because I want to get the unquestionable parts of this merged in.
-rw-r--r--blessings/__init__.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index 8183265..4506869 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -217,10 +217,13 @@ class Terminal(object):
return self._height_and_width()[1]
def _height_and_width(self):
- """Return a tuple of (terminal height, terminal width),
- using TIOCGWINSZ (Terminal I/O-Control: Get Window Size),
- falling back to environment variables (LINES, COLUMNS),
- and 24 x 80 when otherwise unavailable."""
+ """Return a tuple of (terminal height, terminal width).
+
+ Start by trying TIOCGWINSZ (Terminal I/O-Control: Get Window Size),
+ falling back to environment variables (LINES, COLUMNS), and returning
+ (None, None) if those are unavailable or invalid.
+
+ """
# tigetnum('lines') and tigetnum('cols') update only if we call
# setupterm() again.
for descriptor in self._init_descriptor, sys.__stdout__:
@@ -232,9 +235,10 @@ class Terminal(object):
# as when when stdout is piped to another program, fe. tee(1),
# these ioctls will raise IOError
pass
- lines, cols = (int(environ.get('LINES', '24')),
- int(environ.get('COLUMNS', '80')))
- return lines, cols
+ try:
+ return int(environ.get('LINES')), int(environ.get('COLUMNS'))
+ except TypeError:
+ return None, None
@contextmanager
def location(self, x=None, y=None):