Ejemplo n.º 1
0
    def terminal_spinner(*args, **kw):

        nonlocal on_success
        nonlocal on_failure
        nonlocal options

        text_to_display: str
        color: str

        if "text" not in kw.keys():
            text_to_display = choice(options)
        else:
            text_to_display = kw["text"]

        if "color" not in kw.keys():
            color = "red"
        else:
            color = kw["color"]

        sp = Spinner(["🌌", "🚀", "🌌"], 100)
        with yaspin(sp, text=text_to_display, color=color) as sp:
            some_result: Optional[any]
            try:
                some_result = function(*args, **kw)
                sp.write(hype_str(f"{on_success} The task was successful.\n"))

                return some_result
            except Exception as e:

                sp.write(on_failure + " could not be completed.")
                raise (e)
Ejemplo n.º 2
0
with yaspin(Spinners.noise, text="Noise spinner") as sp:
    time.sleep(2)

    sp.spinner = Spinners.arc  # spinner type
    sp.text = "Arc spinner"  # text along with spinner
    sp.color = "yellow"  # spinner color
    sp.side = "right"  # put spinner to the right
    sp.reversal = True

    time.sleep(2)

# + [markdown] nteract={"transient": {"deleting": false}}
# ### Writing messages
# You should not write any message in the terminal using print while spinner
# is open. To write messages in the terminal without any collision with yaspin
# spinner, a ``.write()`` method is provided:
#

# + jupyter={"source_hidden": false, "outputs_hidden": false} nteract={"transient": {"deleting": false}}
with yaspin(text="Downloading images", color="cyan") as sp:
    # task 1
    time.sleep(2)
    sp.write("> image 1 download complete")

    # task 2
    time.sleep(2)
    sp.write("> image 2 download complete")

    # finalize
    sp.ok("")