From f775f4d30ea872945a07eb07c70f78ae57fdef39 Mon Sep 17 00:00:00 2001 From: Peter Ward Date: Sat, 20 Sep 2014 22:03:24 +1000 Subject: render the screen in one print call --- robots/cursesviewer.py | 12 +++++++----- 1 file 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) -- cgit v1.2.3