You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
XMLRuleParser/asciiprint.py

77 lines
2.3 KiB

from typing import Literal, Optional
def cprint(
printValue,
color: Optional[Literal[
"BLACK",
"RED",
"GREEN",
"BROWN",
"BLUE",
"PURPLE",
"CYAN",
"LIGHT_GRAY",
"DARK_GRAY",
"LIGHT_RED",
"LIGHT_GREEN",
"YELLOW",
"LIGHT_BLUE",
"LIGHT_PURPLE",
"LIGHT_CYAN",
"LIGHT_WHITE"
]] = None,
effect: Optional[Literal[
"BOLD",
"FAINT",
"ITALIC",
"UNDERLINE",
"BLINK",
"NEGATIVE",
"CROSSED"
]] = None,
endFormatting: bool = True
):
"""
Prints printValue with added ascii effects.
If the value fails to print with effects, falls back to regular print
params:
printValue (any) : value to print
color (Literal["BLACK","RED","GREEN","BROWN","BLUE","PURPLE","CYAN","LIGHT_GRAY",
"DARK_GRAY","LIGHT_RED","LIGHT_GREEN","YELLOW","LIGHT_BLUE","LIGHT_PURPLE","LIGHT_CYAN","LIGHT_WHITE"])
: sets the color of the text
effect ((Literal["BOLD","FAINT","ITALIC","UNDERLINE","BLINK","NEGATIVE","CROSSED"])
: applies an effect to the text
endFormatting (bool): stop apply effects & resume default after printing.
return:
No return
No exceptions
"""
EFFECTS = {
"BLACK" : "\033[0;30m",
"RED" : "\033[0;31m",
"GREEN" : "\033[0;32m",
"BROWN" : "\033[0;33m",
"BLUE" : "\033[0;34m",
"PURPLE" : "\033[0;35m",
"CYAN" : "\033[0;36m",
"LIGHT_GRAY" : "\033[0;37m",
"DARK_GRAY" : "\033[1;30m",
"LIGHT_RED" : "\033[1;31m",
"LIGHT_GREEN" : "\033[1;32m",
"YELLOW" : "\033[1;33m",
"LIGHT_BLUE" : "\033[1;34m",
"LIGHT_PURPLE" : "\033[1;35m",
"LIGHT_CYAN" : "\033[1;36m",
"LIGHT_WHITE" : "\033[1;37m",
"BOLD" : "\033[1m",
"FAINT" : "\033[2m",
"ITALIC" : "\033[3m",
"UNDERLINE" : "\033[4m",
"BLINK" : "\033[5m",
"NEGATIVE" : "\033[7m",
"CROSSED" : "\033[9m",
"END" : "\033[0m",
}
try:
print(f"{EFFECTS[color] if color != None else ''}{EFFECTS[effect] if effect != None else ''}{printValue}{EFFECTS['END'] if endFormatting else ''}")
except:
print(printValue)