From 95e68280871a587d19645c35d00803e8796c4d70 Mon Sep 17 00:00:00 2001 From: Brennen Raimer <> Date: Sat, 7 Mar 2020 16:27:41 -0500 Subject: [PATCH] fixed suboptimal usage of ipywidgets.Output widget resolves #140 --- halo/halo_notebook.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/halo/halo_notebook.py b/halo/halo_notebook.py index c2e30a4..b1315a9 100644 --- a/halo/halo_notebook.py +++ b/halo/halo_notebook.py @@ -26,26 +26,23 @@ def _make_output_widget(self): from ipywidgets.widgets import Output return Output() - # TODO: using property and setter - def _output(self, text=''): - return ({'name': 'stdout', 'output_type': 'stream', 'text': text},) - def clear(self): if not self.enabled: return self with self.output: - self.output.outputs += self._output('\r') - self.output.outputs += self._output(self.CLEAR_LINE) + print('\r', end="") + print(self.CLEAR_LINE, end="") - self.output.outputs = self._output() return self def _render_frame(self): + self.output.clear_output(wait=True) frame = self.frame() output = '\r{}'.format(frame) + with self.output: - self.output.outputs += self._output(output) + print(output, end="") def start(self, text=None): if text is not None: @@ -105,6 +102,8 @@ def stop_and_persist(self, symbol=' ', text=None): if self._placement == 'right' else (symbol, text) ][0]) + + self.output.clear_output(wait=True) with self.output: - self.output.outputs = self._output(output) + print(output, end="")