Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def colors_simple(sleep=0.7):
# Setup printing
max_len = 25
msg = "[Colors]"
with yaspin(Spinners.dots12) as sp:
for color in COLORS:
spaces_qty = max_len - len(color) - len(msg)
text = "{0}{1}{2}".format(color, " " * spaces_qty, msg)
sp.color = color
sp.text = text
time.sleep(sleep)
def reversed_spinner(sleep=1):
with yaspin(text="Reversed spinner", reversal=True, color="cyan") as sp:
time.sleep(sleep)
sp.spinner = Spinners.line
time.sleep(sleep)
sp.text = "Enjoy!"
sp.ok("☀️ ")
def main():
with yaspin(Spinners.clock, text="Clockwise") as sp:
# Clockwise rotation
time.sleep(3)
# Reverse spin direction
sp.reversal = True
sp.text = "Counterclockwise"
# Counterclockwise rotation
time.sleep(3)
def __getattr__(self, name):
# CLI spinners
if name in SPINNER_ATTRS:
from .spinners import Spinners
sp = getattr(Spinners, name)
self.spinner = sp
# Color Attributes: "color", "on_color", "attrs"
elif name in COLOR_ATTRS:
attr_type = COLOR_MAP[name]
# Call appropriate property setters;
# _color_func is updated automatically by setters.
if attr_type == "attrs":
self.attrs = [name] # calls property setter
if attr_type in ("color", "on_color"):
setattr(self, attr_type, name) # calls property setter
# Side: "left" or "right"
elif name in ("left", "right"):
self.side = name # calls property setter
# Common error for unsupported attributes
else:
raise AttributeError(
("clock", 0.7),
("earth", 0.7),
("moon", 0.7),
("runner", 0.5),
("pong", 1),
("shark", 1.5),
("christmas", 0.5),
]
random.shuffle(params)
# Setup printing
max_len = 45
msg = "[Any spinner you like]"
for name, period in params:
spinner = getattr(Spinners, name)
spaces_qty = max_len - len(name) - len(msg) - len(spinner.frames[0])
text = "{0}{1}{2}".format(name, " " * spaces_qty, msg)
with yaspin(spinner, text=text, color="cyan"):
time.sleep(period)