# Path: yaspin/api.py
# def kbi_safe_yaspin(*args, **kwargs):
#     kwargs["sigmap"] = {signal.SIGINT: default_handler}
#     return Yaspin(*args, **kwargs)
# 
# def yaspin(*args, **kwargs):
#     """Display spinner in stdout.
# 
#     Can be used as a context manager or as a function decorator.
# 
#     Arguments:
#         spinner (base_spinner.Spinner, optional): Spinner object to use.
#         text (str, optional): Text to show along with spinner.
#         color (str, optional): Spinner color.
#         on_color (str, optional): Color highlight for the spinner.
#         attrs (list, optional): Color attributes for the spinner.
#         reversal (bool, optional): Reverse spin direction.
#         side (str, optional): Place spinner to the right or left end
#             of the text string.
#         sigmap (dict, optional): Maps POSIX signals to their respective
#             handlers.
#         timer (bool, optional): Prints a timer showing the elapsed time.
# 
#     Returns:
#         core.Yaspin: instance of the Yaspin class.
# 
#     Raises:
#         ValueError: If unsupported ``color`` is specified.
#         ValueError: If unsupported ``on_color`` is specified.
#         ValueError: If unsupported color attribute in ``attrs``
#             is specified.
#         ValueError: If trying to register handler for SIGKILL signal.
#         ValueError: If unsupported ``side`` is specified.
# 
#     Available text colors:
#         red, green, yellow, blue, magenta, cyan, white.
# 
#     Available text highlights:
#         on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan,
#         on_white, on_grey.
# 
#     Available attributes:
#         bold, dark, underline, blink, reverse, concealed.
# 
#     Example::
# 
#         # Use as a context manager
#         with yaspin():
#             some_operations()
# 
#         # Context manager with text
#         with yaspin(text="Processing..."):
#             some_operations()
# 
#         # Context manager with custom sequence
#         with yaspin(Spinner('-\\|/', 150)):
#             some_operations()
# 
#         # As decorator
#         @yaspin(text="Loading...")
#         def foo():
#             time.sleep(5)
# 
#         foo()
# 
#     """
#     return Yaspin(*args, **kwargs)
# 
# Path: yaspin/signal_handlers.py
# def fancy_handler(signum, frame, spinner):  # pylint: disable=unused-argument
#     """Signal handler, used to gracefully shut down the ``spinner`` instance
#     when specified signal is received by the process running the ``spinner``.
# 
#     ``signum`` and ``frame`` are mandatory arguments. Check ``signal.signal``
#     function for more details.
#     """
#     spinner.red.fail("✘")
#     spinner.stop()
#     sys.exit(0)
# 
# Path: yaspin/spinners.py
# SPINNERS_DATA = pkgutil.get_data(__name__, "data/spinners.json").decode("utf-8")
# def _hook(dct):


import os
import random
import signal
import sys
import time
from yaspin import kbi_safe_yaspin, yaspin
from yaspin.signal_handlers import fancy_handler
from yaspin.spinners import Spinners

        spinner.stop()
        sys.exit(0)

    with yaspin(sigmap={signal.SIGINT: my_handler}).toggle8 as sp:
        sp.text = "Tossing a coin... Press Control-C to view the result"
        time.sleep(10)
        sp.write("The coin has disappeared")


def handling_multiple_signals():
    def my_handler(signum, frame, spinner):
        if signum == int(signal.SIGUSR1):
            spinner.green.ok("[SIGUSR1]")
        if signum == int(signal.SIGTERM):
            spinner.red.ok("[SIGTERM]")

        spinner.stop()
        sys.exit(0)

    sigmap = {signal.SIGUSR1: my_handler, signal.SIGTERM: my_handler}

    with yaspin(sigmap=sigmap, text="Handling SIGUSR1 and SIGTERM") as sp:
        sp.write("Send signals using `kill` command")
        sp.write("E.g. $ kill -USR1 {0}".format(os.getpid()))
        time.sleep(60)
        sp.write("No signal received")


def ignore_signal():

# Path: yaspin/api.py
# def kbi_safe_yaspin(*args, **kwargs):
#     kwargs["sigmap"] = {signal.SIGINT: default_handler}
#     return Yaspin(*args, **kwargs)
# 
# def yaspin(*args, **kwargs):
#     """Display spinner in stdout.
# 
#     Can be used as a context manager or as a function decorator.
# 
#     Arguments:
#         spinner (base_spinner.Spinner, optional): Spinner object to use.
#         text (str, optional): Text to show along with spinner.
#         color (str, optional): Spinner color.
#         on_color (str, optional): Color highlight for the spinner.
#         attrs (list, optional): Color attributes for the spinner.
#         reversal (bool, optional): Reverse spin direction.
#         side (str, optional): Place spinner to the right or left end
#             of the text string.
#         sigmap (dict, optional): Maps POSIX signals to their respective
#             handlers.
#         timer (bool, optional): Prints a timer showing the elapsed time.
# 
#     Returns:
#         core.Yaspin: instance of the Yaspin class.
# 
#     Raises:
#         ValueError: If unsupported ``color`` is specified.
#         ValueError: If unsupported ``on_color`` is specified.
#         ValueError: If unsupported color attribute in ``attrs``
#             is specified.
#         ValueError: If trying to register handler for SIGKILL signal.
#         ValueError: If unsupported ``side`` is specified.
# 
#     Available text colors:
#         red, green, yellow, blue, magenta, cyan, white.
# 
#     Available text highlights:
#         on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan,
#         on_white, on_grey.
# 
#     Available attributes:
#         bold, dark, underline, blink, reverse, concealed.
# 
#     Example::
# 
#         # Use as a context manager
#         with yaspin():
#             some_operations()
# 
#         # Context manager with text
#         with yaspin(text="Processing..."):
#             some_operations()
# 
#         # Context manager with custom sequence
#         with yaspin(Spinner('-\\|/', 150)):
#             some_operations()
# 
#         # As decorator
#         @yaspin(text="Loading...")
#         def foo():
#             time.sleep(5)
# 
#         foo()
# 
#     """
#     return Yaspin(*args, **kwargs)
# 
# Path: yaspin/signal_handlers.py
# def fancy_handler(signum, frame, spinner):  # pylint: disable=unused-argument
#     """Signal handler, used to gracefully shut down the ``spinner`` instance
#     when specified signal is received by the process running the ``spinner``.
# 
#     ``signum`` and ``frame`` are mandatory arguments. Check ``signal.signal``
#     function for more details.
#     """
#     spinner.red.fail("✘")
#     spinner.stop()
#     sys.exit(0)
# 
# Path: yaspin/spinners.py
# SPINNERS_DATA = pkgutil.get_data(__name__, "data/spinners.json").decode("utf-8")
# def _hook(dct):


# Path: examples/signals.py
import os
import random
import signal
import sys
import time
from yaspin import kbi_safe_yaspin, yaspin
from yaspin.signal_handlers import fancy_handler
from yaspin.spinners import Spinners


        spinner.stop()
        sys.exit(0)

    with yaspin(sigmap={signal.SIGINT: my_handler}).toggle8 as sp:
        sp.text = "Tossing a coin... Press Control-C to view the result"
        time.sleep(10)
        sp.write("The coin has disappeared")


def handling_multiple_signals():
    def my_handler(signum, frame, spinner):
        if signum == int(signal.SIGUSR1):
            spinner.green.ok("[SIGUSR1]")
        if signum == int(signal.SIGTERM):
            spinner.red.ok("[SIGTERM]")

        spinner.stop()
        sys.exit(0)

    sigmap = {signal.SIGUSR1: my_handler, signal.SIGTERM: my_handler}

    with yaspin(sigmap=sigmap, text="Handling SIGUSR1 and SIGTERM") as sp:
        sp.write("Send signals using `kill` command")
        sp.write("E.g. $ kill -USR1 {0}".format(os.getpid()))
        time.sleep(60)
        sp.write("No signal received")


def ignore_signal():

    with yaspin(sigmap={signal.SIGINT: signal.SIG_IGN}, text="You can't interrupt me!"):