diff options
author | Peter Ward <peteraward@gmail.com> | 2014-09-20 22:03:24 +1000 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2014-09-20 22:03:24 +1000 |
commit | f775f4d30ea872945a07eb07c70f78ae57fdef39 (patch) | |
tree | 979b87f86397e90e832b65812af4fe590ede870a | |
parent | cada1ca46ef5ae37c5fdde7af65252b0ba4ef2ce (diff) |
render the screen in one print call
-rw-r--r-- | robots/cursesviewer.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/robots/cursesviewer.py b/robots/cursesviewer.py index 257c425..d369a80 100644 --- a/robots/cursesviewer.py +++ b/robots/cursesviewer.py @@ -26,16 +26,17 @@ class CursesViewer: )) def draw_board(self, state): - print(self.terminal.clear, end='') + stdout = [] + stdout.append(self.terminal.clear) players = [] for name, colour in sorted(self.player_colours.items()): fn = getattr(self.terminal, 'on_' + colour) players.append(fn(name)) - print(' '.join(players)) + stdout.append(' '.join(players) + '\n') width = len(state.board[0]) * 3 - print(Box.TL + Box.H * width + Box.TR) + stdout.append(Box.TL + Box.H * width + Box.TR + '\n') for y, row in enumerate(state.board): output = [] @@ -70,9 +71,10 @@ class CursesViewer: value = func(value) output.append(value) - print(Box.V + ''.join(output) + Box.V) + stdout.append(Box.V + ''.join(output) + Box.V + '\n') - print(Box.BL + Box.H * width + Box.BR) + stdout.append(Box.BL + Box.H * width + Box.BR + '\n') + print('\n'.join(stdout), end='') def run(self): limiter = rate_limit(10) |