How to use the yaspin.spinners function in yaspin

To help you get started, we’ve selected a few yaspin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erayerdin / tgcli / tgcli / cli / bot / send.py View on Github external
def send_message(
    session: tgcli.request.bot.BotSession, request: tgcli.request.bot.BotRequest
):
    """
    Sends message using Yaspin.
    """
    with yaspin.yaspin(yaspin.spinners.Spinners.clock) as spinner:
        spinner.text = "Sending message..."
        response = session.send(request)

        if response.ok:
            spinner.text = "Message was sent successfully."
            spinner.ok("✔️ ")
        else:
            data = response.json()

            code = data.get("error_code", "Unknown")
            description = data.get("description", "No description found.")
            spinner.write(
                "{c.bold_red}Error Code:{c.reset} {}".format(code, c=colorful)
            )
            spinner.write(
                "{c.bold_red}Error Details:{c.reset} {}".format(description, c=colorful)
github pypa / pipenv / pipenv / vendor / vistir / misc.py View on Github external
elif isinstance(cmd, (list, tuple)):
            cmd = [c.encode("utf-8") for c in cmd]
    if not isinstance(cmd, Script):
        cmd = Script.parse(cmd)
    if nospin is False:
        try:
            from yaspin import yaspin
            from yaspin import spinners
        except ImportError:
            raise RuntimeError(
                "Failed to import spinner! Reinstall vistir with command:"
                " pip install --upgrade vistir[spinner]"
            )
        else:
            spinner = yaspin
            animation = spinners.Spinners.dots
    else:

        @contextmanager
        def spinner(spin_type, text):
            class FakeClass(object):
                def __init__(self, text=""):
                    self.text = text

                def ok(self, text):
                    return

                def write(self, text):
                    print(text)

            myobj = FakeClass(text)
            yield myobj