diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-10-12 19:14:41 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-12 19:30:32 +0300 |
commit | 9fd6ba3d79e2e3f5a1a022cf334528deeb43f793 (patch) | |
tree | 4b6f5fe3a46aa6b302b0fc176b82010fa6a77cdd | |
parent | 549152b4b25a1ff2338896e40859903e19ff48a8 (diff) | |
download | ttystatus-9fd6ba3d79e2e3f5a1a022cf334528deeb43f793.tar.gz |
Get rid of ASCII control chars in values
-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()) |