diff options
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | ttystatus/status.py | 11 |
2 files changed, 16 insertions, 2 deletions
@@ -1,6 +1,13 @@ NEWS file for ttystatus ======================= +Version 0.30, released UNRELEASED +--------------------------------- + +* Strip ASCII control characters from displayed output (but expand + TABs) in widget values. This avoids TABs making values longer than + expected, and terminals getting confused by control sequences. + Version 0.29, released 2015-10-10 --------------------------------- 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()) |