summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-10-04 22:31:57 +0300
committerLars Wirzenius <liw@liw.fi>2015-10-04 22:31:57 +0300
commitbf94e5dd4846020055dd80d56b85005e2befb833 (patch)
treea6f6322d652f5439726e674fd4343bb20d6965d9
parentc20e1d3434610c425eae62d42ab59017a042aba7 (diff)
downloadttystatus-bf94e5dd4846020055dd80d56b85005e2befb833.tar.gz
Disable output if terminal lacks capabilities
-rw-r--r--ttystatus/messager.py5
-rw-r--r--ttystatus/tty.py4
2 files changed, 8 insertions, 1 deletions
diff --git a/ttystatus/messager.py b/ttystatus/messager.py
index 5f08690..f9ab912 100644
--- a/ttystatus/messager.py
+++ b/ttystatus/messager.py
@@ -46,6 +46,9 @@ class Messager(object):
except IOError:
self._enabled = False
+ if not self._terminal.has_capabilities():
+ self._enabled = False
+
self._area = ttystatus.AreaManager()
self._area.set_terminal(self._terminal)
@@ -122,6 +125,6 @@ class Messager(object):
def finish(self):
'''Finalize output.'''
- if self._cached_message is not None:
+ if self._enabled and self._cached_message is not None:
self.write(self._cached_message)
self._terminal.write('\n')
diff --git a/ttystatus/tty.py b/ttystatus/tty.py
index f37b825..21e75cc 100644
--- a/ttystatus/tty.py
+++ b/ttystatus/tty.py
@@ -31,6 +31,10 @@ class PhysicalTerminal(object):
self._terminal = open('/dev/tty', 'wb')
curses.setupterm(None, self._terminal.fileno())
+ def has_capabilities(self):
+ return all(curses.tigetstr(x) is not None
+ for x in ['cuu', 'cud', 'cr', 'el'])
+
def get_up_sequence(self):
return curses.tparm(curses.tigetstr('cuu'), 1)