Skip to main content

ColorPattern

PyPI - Downloads Pepy Total Downlods

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 text

Installation

You can install ColorPattern using pip:

pip install colorpattern

Usage

Set the patterns whith SetPatterns(<patterns>,<options>)

Use start_color(<patterns>) for initialize the color print, and end_color() for stop colorization.

Example

from colorpattern import *

def main():
    # Define your color patterns
    pattern1 = 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 patterns
    print("\nSTART COLORIZED PRINT")
    print('-----------------------')
    start_color([pattern1, pattern2, pattern3, email, strike, italic,blink])

    # Use the custom print function with colorization
    print('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 function
    end_color()
    print("\nNORMAL PRINT")

    # Now, printing returns to normal
    print('-----------------------')
    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 necessary
    new_pattern = SetPattern(r'new pattern', color=Fore.LIGHTCYAN_EX)

    # Use the custom print function with new patterns
    print("\nSTART COLORIZED PRINT AGAIN")
    start_color([pattern1, new_pattern])
    print('-----------------------')
    print('This is a new pattern. 123456')

    # End colorization and restore the original print function
    end_color()
    print("\nNORMAL PRINT AGAIN")
    # Now, printing returns to normal even with the new patterns
    print('-----------------------')
    print('This is a normal message again. 12345')

if __name__ == "__main__":
    main()

Patterns

  • pattern: 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 to True for underlining matched text.

  • strike: Set to True for strikethrough matched text.

  • blink: Set to True for blink matched text.

  • italic: Set to True for italic matched text.

Colors (colorama):

Text Colors (Fore):

  • Fore.BLACK

  • Fore.RED

  • Fore.GREEN

  • Fore.YELLOW

  • Fore.BLUE

  • Fore.MAGENTA

  • Fore.CYAN

  • Fore.WHITE

  • Fore.LIGHTBLACK_EX

  • Fore.LIGHTRED_EX

  • Fore.LIGHTGREEN_EX

  • Fore.LIGHTYELLOW_EX

  • Fore.LIGHTBLUE_EX

  • Fore.LIGHTMAGENTA_EX

  • Fore.LIGHTCYAN_EX

  • Fore.LIGHTWHITE_EX

  • Fore.RESET

Background Colors (Back):

  • Back.BLACK

  • Back.RED

  • Back.GREEN

  • Back.YELLOW

  • Back.BLUE

  • Back.MAGENTA

  • Back.CYAN

  • Back.WHITE

  • Back.LIGHTBLACK_EX

  • Back.LIGHTRED_EX

  • Back.LIGHTGREEN_EX

  • Back.LIGHTYELLOW_EX

  • Back.LIGHTBLUE_EX

  • Back.LIGHTMAGENTA_EX

  • Back.LIGHTCYAN_EX

  • Back.LIGHTWHITE_EX

  • Back.RESET

Text Styles (Style):

  • Style.RESET_ALL

  • Style.BRIGHT

  • Style.DIM

  • Style.NORMAL

License

This project is licensed under the GNU-GLP,3 License - see the LICENSE file for details.

Metadata

Release files for colorpattern 1.4.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colorpattern 1.4.7
File Size Uploaded
colorpattern-1.4.7.tar.gz 43.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colorpattern 1.4.7
File Interpreter ABI Platform
colorpattern-1.4.7-py3-none-any.whl Python 3 none any Details

Total release size: 74.8 kB

Release files / colorpattern-1.4.7.tar.gz

Download URL colorpattern-1.4.7.tar.gz
Size 43.9 kB
Tags Source
SHA-256 checksum
How to use checksums
dd9b846f4b8cde3e7cf452fe4ba1fec118c2589b605d05cb63772990202c4aae
BLAKE2b-256 checksum
How to use checksums
54632fb9485f248e550f0e5a5e32c443eb1dabb48aef099a0e2c4b758cd5d76d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / colorpattern-1.4.7-py3-none-any.whl

Download URL colorpattern-1.4.7-py3-none-any.whl
Size 30.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5df7f33543e460c808eff9c464bb9586ebdaf3d20a5651c23438f1e312cf2f0
BLAKE2b-256 checksum
How to use checksums
56616ceb53e7bd65fb32e1ce940074bbb8bb0400848ab99cafd40a087a91f66b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.4.7 This release

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page