diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-09-26 23:16:32 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-09-26 23:16:32 +0300 |
commit | 25ddb866268f0b3d1798c1de81b65e7a6cf33e61 (patch) | |
tree | 34312c84fb88dbf487b91f6f4d012a77f0edb60c | |
parent | 8fc68b301bcd5c6ca2d95845c38ce75ca8feafe4 (diff) | |
download | ttystatus-25ddb866268f0b3d1798c1de81b65e7a6cf33e61.tar.gz |
Refactor for clarification, then fix one-line output
-rw-r--r-- | ttystatus/messager.py | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/ttystatus/messager.py b/ttystatus/messager.py index 71013e3..d5dce46 100644 --- a/ttystatus/messager.py +++ b/ttystatus/messager.py @@ -109,17 +109,22 @@ class Messager(object): self._first_output = False if rows: + up = curses.tparm(curses.tigetstr('cuu'), 1) + down = curses.tparm(curses.tigetstr('cud'), 1) + cr = curses.tigetstr('cr') + el = curses.tigetstr('el') + raw_parts.extend([ - curses.tparm(curses.tigetstr('cuu'), len(rows) - 1), # go up - curses.tigetstr('cr'), # beginning of line - curses.tigetstr('el'), # erase to end of line + up * (len(rows) - 1), + cr, + el, rows[0][:self.width], ]) for row in rows[1:]: raw_parts.extend([ - curses.tparm(curses.tigetstr('cud'), 1), # down one line - curses.tigetstr('cr'), # beginning of line - curses.tigetstr('el'), # erase to end of line + down, + cr, + el, row[:self.width], ]) @@ -131,24 +136,32 @@ class Messager(object): def clear(self): '''Remove current message from terminal.''' + if self._first_output: + return + rows = self._cached_msg.split('\n') raw_parts = [] if rows: + up = curses.tparm(curses.tigetstr('cuu'), 1) + down = curses.tparm(curses.tigetstr('cud'), 1) + cr = curses.tigetstr('cr') + el = curses.tigetstr('el') + raw_parts.extend([ - curses.tparm(curses.tigetstr('cuu'), len(rows) - 1), # go up - curses.tigetstr('cr'), # beginning of line - curses.tigetstr('el'), # erase to end of line + up * (len(rows) - 1), + cr, + el, ]) for row in rows[1:]: raw_parts.extend([ - curses.tparm(curses.tigetstr('cud'), 1), # down one line - curses.tigetstr('cr'), # beginning of line - curses.tigetstr('el'), # erase to end of line + down, + cr, + el, ]) raw_parts.extend([ - curses.tparm(curses.tigetstr('cuu'), len(rows) - 1), # go up + up * (len(rows) - 1), ]) raw = ''.join(raw_parts) |