Beispiel #1
0
    def __init__(self, text='', color='cyan', spinner=None,
                 animation=None, placement='left', interval=-1, enabled=True, stream=sys.stdout):
        """Constructs the Halo object.
        Parameters
        ----------
        text : str, optional
            Text to display.
        color : str, optional
            Color of the text to display.
        spinner : str|dict, optional
            String or dictionary representing spinner. String can be one of 60+ spinners
            supported.
        animation: str, optional
            Animation to apply if text is too large. Can be one of `bounce`, `marquee`.
            Defaults to ellipses.
        placement: str, optional
            Side of the text to place the spinner on. Can be `left` or `right`.
            Defaults to `left`.
        interval : integer, optional
            Interval between each frame of the spinner in milliseconds.
        enabled : boolean, optional
            Spinner enabled or not.
        stream : io, optional
            Output.
        """
        self._color = color
        self._animation = animation

        self.spinner = spinner
        self.text = text

        self._interval = int(interval) if int(interval) > 0 else self._spinner['interval']
        self._stream = stream

        self.placement = placement
        self._frame_index = 0
        self._text_index = 0
        self._spinner_thread = None
        self._stop_spinner = None
        self._spinner_id = None
        self._enabled = enabled  # Need to check for stream

        environment = get_environment()

        def clean_up():
            """Handle cell execution"""
            self.stop()

        if environment in ('ipython', 'jupyter'):
            from IPython import get_ipython

            ip = get_ipython()
            ip.events.register('post_run_cell', clean_up)
        elif environment == 'terminal':
            atexit.register(clean_up)
Beispiel #2
0
    def __init__(
        self,
        text="",
        color="cyan",
        text_color=None,
        spinner=None,
        animation=None,
        placement="left",
        interval=-1,
        enabled=True,
        stream=sys.stdout,
    ):
        """Constructs the Halo object.
        Parameters
        ----------
        text : str, optional
            Text to display.
        text_color : str, optional
            Color of the text.
        color : str, optional
            Color of the text to display.
        spinner : str|dict, optional
            String or dictionary representing spinner. String can be one of 60+ spinners
            supported.
        animation: str, optional
            Animation to apply if text is too large. Can be one of `bounce`, `marquee`.
            Defaults to ellipses.
        placement: str, optional
            Side of the text to place the spinner on. Can be `left` or `right`.
            Defaults to `left`.
        interval : integer, optional
            Interval between each frame of the spinner in milliseconds.
        enabled : boolean, optional
            Spinner enabled or not.
        stream : io, optional
            Output.
        """

        # To reset Values in deleter
        self.reset_values = {"text": text,
                             "color": color,
                             "text_color": text_color,
                             "spinner": spinner,
                             "animation": animation,
                             "placement": placement, }

        self._symbol = "  "
        self._stop_persist = False

        self._color = color
        self._animation = animation

        self.spinner = spinner
        self.text = text
        self._text_color = text_color

        self._interval = (
            int(interval) if int(interval) > 0 else self._spinner["interval"]
        )
        self._stream = stream

        self.placement = placement
        self._frame_index = 0
        self._text_index = 0
        self._spinner_thread = None
        self._stop_spinner = None
        self._spinner_id = None
        self.enabled = enabled

        environment = get_environment()

        def clean_up():
            """Handle cell execution"""
            self.stop()

        if environment in ("ipython", "jupyter"):
            from IPython import get_ipython

            ip = get_ipython()
            ip.events.register("post_run_cell", clean_up)
        else:  # default terminal
            atexit.register(clean_up)