summaryrefslogtreecommitdiff
path: root/blessings/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'blessings/__init__.py')
-rw-r--r--blessings/__init__.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/blessings/__init__.py b/blessings/__init__.py
index 673fa26..abf44c1 100644
--- a/blessings/__init__.py
+++ b/blessings/__init__.py
@@ -1,17 +1,7 @@
-"""
-(c) 2012 Erik Rose
-MIT Licensed
-https://github.com/erikrose/blessings
-"""
-import curses
-import os
-import struct
-import sys
from contextlib import contextmanager
+import curses
from curses import setupterm, tigetnum, tigetstr, tparm
from fcntl import ioctl
-from platform import python_version_tuple
-from termios import TIOCGWINSZ
try:
from io import UnsupportedOperation as IOUnsupportedOperation
@@ -20,6 +10,12 @@ except ImportError:
"""A dummy exception to take the place of Python 3's
``io.UnsupportedOperation`` in Python 2"""
+from os import isatty, environ
+from platform import python_version_tuple
+import struct
+import sys
+from termios import TIOCGWINSZ
+
__all__ = ['Terminal']
@@ -80,12 +76,13 @@ class Terminal(object):
stream = sys.__stdout__
try:
stream_descriptor = (stream.fileno() if hasattr(stream, 'fileno')
- and callable(stream.fileno) else None)
+ and callable(stream.fileno)
+ else None)
except IOUnsupportedOperation:
stream_descriptor = None
self._is_a_tty = (stream_descriptor is not None and
- os.isatty(stream_descriptor))
+ isatty(stream_descriptor))
self._does_styling = ((self.is_a_tty or force_styling) and
force_styling is not None)
@@ -101,7 +98,7 @@ class Terminal(object):
# init sequences to the stream if it has a file descriptor, and
# send them to stdout as a fallback, since they have to go
# somewhere.
- setupterm(kind or os.environ.get('TERM', 'unknown'),
+ setupterm(kind or environ.get('TERM', 'unknown'),
self._init_descriptor)
self.stream = stream
@@ -327,6 +324,8 @@ class Terminal(object):
# access to it.
colors = tigetnum('colors') # Returns -1 if no color support, -2 if no
# such cap.
+ # self.__dict__['colors'] = ret # Cache it. It's not changing.
+ # (Doesn't work.)
return colors if colors >= 0 else 0
def _resolve_formatter(self, attr):