Package: colorpattern
ColorPattern is a Python module designed for enhancing text output in
the console by applying color to specific patterns. It offers a flexible
way to define patterns and apply different text colors, background
colors, styles, underlines and other options to predefined patterns.Use regular expressions to define the pattern to color. With the color
pattern initialized, any console output that matches the pattern will
have the defined styles applied to it.Since Version 1.4.1 can strikethrough, blink text and italic textInstallationYou can install ColorPattern using pip:pip install colorpatternUsageSet the patterns whithSetPatterns(<patterns>,<options>)Usestart_color(<patterns>)for initialize the color print, andend_color()for stop colorization.Examplefromcolorpatternimport*defmain():# Define your color patternspattern1=SetPattern(r'\d+',color=Fore.GREEN)pattern2=SetPattern(r'Colorpattern',color=Fore.LIGHTRED_EX,underline=True)pattern3=SetPattern(r'Croketillo',color=Fore.BLACK,back=Back.LIGHTWHITE_EX,style=Style.BRIGHT)email=SetPattern(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b',color=Fore.BLUE)strike=SetPattern(r'NEW!!!',strikethrough=True)blink=SetPattern(r'BLINK',blink=True)italic=SetPattern(r'ITALIC TEXT',italic=True)# Initialize colorization and get the original print function and applied patternsprint("\nSTART COLORIZED PRINT")print('-----------------------')start_color([pattern1,pattern2,pattern3,email,strike,italic,blink])# Use the custom print function with colorizationprint('Colorpattern v1.4.6')print('By Croketillo - croketillo@gmail.com')print('NEW!!! - NOW YOU CAN INCLUDE STRIKETHROUGH IN PATTERNS')print('This is a BLINK and ITALIC TEXT test')# End colorization and restore the original print functionend_color()print("\nNORMAL PRINT")# Now, printing returns to normalprint('-----------------------')print('Colorpattern v1.4.5')print('By Croketillo - croketillo@gmail.com')print('NEW!!! - NOW YOU CAN INCLUDE STRIKETHROUGH IN PATTERNS')print('This is a BLINK and ITALIC TEXT test')# You can re-enable colorization with new patterns if necessarynew_pattern=SetPattern(r'new pattern',color=Fore.LIGHTCYAN_EX)# Use the custom print function with new patternsprint("\nSTART COLORIZED PRINT AGAIN")start_color([pattern1,new_pattern])print('-----------------------')print('This is a new pattern. 123456')# End colorization and restore the original print functionend_color()print("\nNORMAL PRINT AGAIN")# Now, printing returns to normal even with the new patternsprint('-----------------------')print('This is a normal message again. 12345')if__name__=="__main__":main()Patternspattern: Regular expression pattern to match in the text.color: Text color (e.g., ‘green’, ‘red’, ‘yellow’).back: Background color (e.g., ‘black’, ‘blue’, ‘white’).style: Text style (e.g., ‘bright’, ‘dim’, ‘reset_all’).underline: Set toTruefor underlining matched text.strike: Set toTruefor strikethrough matched text.blink: Set toTruefor blink matched text.italic: Set toTruefor italic matched text.Colors (colorama):Text Colors (Fore):Fore.BLACKFore.REDFore.GREENFore.YELLOWFore.BLUEFore.MAGENTAFore.CYANFore.WHITEFore.LIGHTBLACK_EXFore.LIGHTRED_EXFore.LIGHTGREEN_EXFore.LIGHTYELLOW_EXFore.LIGHTBLUE_EXFore.LIGHTMAGENTA_EXFore.LIGHTCYAN_EXFore.LIGHTWHITE_EXFore.RESETBackground Colors (Back):Back.BLACKBack.REDBack.GREENBack.YELLOWBack.BLUEBack.MAGENTABack.CYANBack.WHITEBack.LIGHTBLACK_EXBack.LIGHTRED_EXBack.LIGHTGREEN_EXBack.LIGHTYELLOW_EXBack.LIGHTBLUE_EXBack.LIGHTMAGENTA_EXBack.LIGHTCYAN_EXBack.LIGHTWHITE_EXBack.RESETText Styles (Style):Style.RESET_ALLStyle.BRIGHTStyle.DIMStyle.NORMALLicenseThis project is licensed under the GNU-GLP,3 License - see the LICENSE
file for details.