Created
December 29, 2022 12:13
-
-
Save hasanisaeed/36e69933b8a55414f123e0fcf2b7aff9 to your computer and use it in GitHub Desktop.
Color printing in the terminal!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NO_COLOR = "0" # Text Reset | |
BLACK = "0;30" # Black | |
RED = "0;31" # Red | |
GREEN = "0;32" # Green | |
YELLOW = "0;33" # Yellow | |
BLUE = "0;34" # Blue | |
PURPLE = "0;35" # Purple | |
CYAN = "0;36" # Cyan | |
WHITE = "0;37" # White | |
def print_colored(text, color: str = "0"): | |
print(f"\033[{color}m{text}\033[0m") | |
# ---------- Examples ---------- | |
print_colored(">> Hello World with NO_COLOR", NO_COLOR) | |
print_colored(">> Hello World with BLACK", BLACK) | |
print_colored(">> Hello World with RED", RED) | |
print_colored(">> Hello World with GREEN", GREEN) | |
print_colored(">> Hello World with YELLOW", YELLOW) | |
print_colored(">> Hello World with BLUE", BLUE) | |
print_colored(">> Hello World with PURPLE", PURPLE) | |
print_colored(">> Hello World with CYAN", CYAN) | |
print_colored(">> Hello World with WHITE", WHITE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: