Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed suboptimal usage of ipywidgets.Output widget #143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions halo/halo_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import halo.cursor as cursor

from halo import Halo
from halo._utils import colored_frame, decode_utf_8_text

from halo._utils import colored_frame, decode_utf_8_text, is_text_type
from spinners.spinners import Spinners

class HaloNotebook(Halo):
def __init__(
Expand Down Expand Up @@ -40,26 +40,23 @@ def _make_output_widget(self):

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)
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:
Expand Down Expand Up @@ -114,9 +111,13 @@ def stop_and_persist(self, symbol=" ", text=None):

self.stop()

output = "\r{} {}\n".format(
*[(text, symbol) if self._placement == "right" else (symbol, text)][0]
)
output = '\r{} {}\n'.format(*[
(text, symbol)
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="")