Add color selection and printing functions with documentation

This commit is contained in:
lasseedfast 2024-12-02 09:51:13 +01:00
parent 27d01aeb0f
commit d313c78b5b

View File

@ -1,40 +1,14 @@
def print_green(*args):
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[92m{text}\033[0m")
def print_red(*args):
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[91m{text}\033[0m")
def print_yellow(*args):
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[93m{text}\033[0m")
def print_blue(*args):
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[94m{text}\033[0m")
def print_purple(*args):
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[95m{text}\033[0m")
def choose_color(last_color_index):
"""
Selects the next color in a predefined sequence of colors.
Args:
last_color_index (int): The index of the last color used.
Returns:
tuple: A tuple containing the ANSI escape code for the selected color (str)
and the index of the selected color (int).
"""
colors = {
"blue": "\033[94m",
"green": "\033[92m",
@ -47,7 +21,70 @@ def choose_color(last_color_index):
color = color_keys[color_index]
return colors[color], color_index
def print_green(*args):
"""
Prints the provided arguments in green.
"""
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[92m{text}\033[0m")
def print_red(*args):
"""
Prints the provided arguments in red.
"""
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[91m{text}\033[0m")
def print_yellow(*args):
"""
Prints the provided arguments in yellow.
"""
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[93m{text}\033[0m")
def print_blue(*args):
"""
Prints the provided arguments in blue.
"""
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[94m{text}\033[0m")
def print_purple(*args):
"""
Prints the provided arguments in purple.
"""
text = ""
for arg in args:
text += str(arg) + " "
print(f"\033[95m{text}\033[0m")
def print_rainbow(*args):
"""
Prints the provided arguments in a rainbow of colors.
Args:
*args: Variable length argument list. Each argument can be a string, list, or dictionary.
- If the argument is a list, each element in the list will be printed in a different color.
- If the argument is a dictionary, each key-value pair will be printed in a different color.
- If the argument is a string or any other type, it will be printed in a different color.
Returns:
None
"""
color_index = -1
text = ""
for arg in args: