summaryrefslogtreecommitdiff
path: root/ttystatus
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-10-12 19:14:41 +0300
committerLars Wirzenius <liw@liw.fi>2015-10-12 19:30:32 +0300
commit9fd6ba3d79e2e3f5a1a022cf334528deeb43f793 (patch)
tree4b6f5fe3a46aa6b302b0fc176b82010fa6a77cdd /ttystatus
parent549152b4b25a1ff2338896e40859903e19ff48a8 (diff)
downloadttystatus-9fd6ba3d79e2e3f5a1a022cf334528deeb43f793.tar.gz
Get rid of ASCII control chars in values
Diffstat (limited to 'ttystatus')
-rw-r--r--ttystatus/status.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/ttystatus/status.py b/ttystatus/status.py
index 46e291f..148b8ff 100644
--- a/ttystatus/status.py
+++ b/ttystatus/status.py
@@ -117,16 +117,23 @@ class TerminalStatus(object):
for i, w in enumerate(widget_row):
if w.static_width:
- texts[i] = w.render(0)
+ texts[i] = self._make_safe(w.render(0))
remaining -= len(texts[i])
for i, w in enumerate(widget_row):
if not w.static_width:
- texts[i] = w.render(remaining)
+ texts[i] = self._make_safe(w.render(remaining))
remaining -= len(texts[i])
return (''.join(texts))[:max_chars]
+ def _make_safe(self, line):
+ '''Expand TABs, remove all other ASCII control characters.'''
+ ASCII_SPACE = 32
+ return ''.join(
+ c if ord(c) >= ASCII_SPACE else ''
+ for c in line.expandtabs())
+
def _write(self):
'''Render and output current state of all widgets.'''
self._m.write(self._render())