# from console_color import RGB, Fore, Style, cprint, create_print
from console_color import *
cprint('red: RGB.RED', RGB.RED)
cprint('red: #FF0000', '#FF0000') # It doesn't matter for string upper or lower, and if you don't want to add the sign of #, it's ok too.
cprint('red: (255, 0, 0)', (255, 0, 0))
cprint('red: RGB.RED', bg=RGB.RED)
cprint('red: #FF0000', bg='#ff0000')
cprint('red: (255, 0, 0)', bg=(255, 0, 0))
cprint('red: RGB.RED, RGB.YELLOW', RGB.RED, RGB.YELLOW)
cprint('red: FF0000, #FFFF00', 'FF0000', '#FFFF00')
cprint('red: (255, 0, 0), (255, 255, 0)', (255, 0, 0), (255, 255, 0))
cprint('Italic', style=Style.ITALIC) # The ipynb seems not to show both italic and strike well.
cprint('Italic and Bold', style=Style.BOLD + Style.ITALIC)
cprint('Strike', style=Style.STRIKE)
set pf = False
print(f"123 {cprint('Fore=Red, bg=Yellow, Style=Italic and Bold', RGB.RED, RGB.YELLOW, Style.BOLD + Style.ITALIC, False)} 456")
print(f"123 {cprint('BOLD', style=Style.BOLD, pf=False)} 456")
ry_print = create_print(fore='FF0000', bg='#FFFF00') # ry: red and yellow
inner_ry_text = create_print('FF0000', '#FFFF00', Style.BOLD + Style.ITALIC, pf=False)
msg = "fore='FF0000', bg='#FFFF00'"
print(msg)
ry_print(msg)
print('...')
ry_print(msg)
print(f'normal text ... {inner_ry_text("fore=red, bg=yellow, style=bold+italic")} !!!')
from itertools import permutations
row_string = ''
for count, rgb in enumerate(permutations((_ for _ in range(0, 256, 40)), 3)):
count += 1
fore_color = RGB.complementary_color(rgb)
row_string += cprint(f'{RGB.tuple2hex_str(rgb)} ', fore_color, rgb, pf=False)
if count % 7 == 0:
print(row_string),
row_string = ''
print(row_string) if len(row_string) > 0 else None
If you have no idea how to use this library, you can input by indicate, and then it will tell you what the grammar you should write.
text = chr(34) + input('text:') + chr(34)
in_fore = input('Fore (#XXYYRR) (r, g, b):')
if in_fore:
in_fore = str(eval(in_fore)) if in_fore.find(',') != -1 else chr(34) + in_fore + chr(34)
in_bg = input('Background (#XXYYRR) (r, g, b):')
if in_bg:
in_bg = str(eval(in_bg)) if in_bg.find(',') != -1 else chr(34) + in_bg + chr(34)
in_style = input('Style (BOLD, ITALIC, URL, STRIKE) sep=" ":').split(' ')
if in_style:
in_style = '+'.join([f'Style.{_.upper()}' for _ in in_style])
print_cmd = f"cprint({text}{', fore=' + in_fore if in_fore else ''}" \
f"{', bg=' + in_bg if in_bg else ''}" \
f"{', style=' + in_style if in_style else ''})"
print(f'grammar: {cprint(print_cmd, RGB.GREEN, RGB.BLACK, pf=False)}')
exec(print_cmd)