diff --git a/README.md b/README.md index cd642f5..d440d3e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 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, and underlines to matching text in the output. -In Version 1.4 can strikethrough +In Version 1.4.1 can strikethrough, blink text and italic text ## Installation @@ -25,16 +25,19 @@ def main(): 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]) + start_color([pattern1, pattern2, pattern3, email, strike, italic,blink]) # Use the custom print function with colorization - print('Colorpattern v1.4') + print('Colorpattern v1.4.1') 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() @@ -42,8 +45,10 @@ def main(): # Now, printing returns to normal print('-----------------------') - print('Colorpattern v1.4') + print('Colorpattern v1.4.1') 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) @@ -60,11 +65,10 @@ def main(): print("\nNORMAL PRINT AGAIN") # Now, printing returns to normal even with the new patterns print('-----------------------') - print('This is a normal message again.') + print('This is a normal message again. 12345') if __name__ == "__main__": main() - ``` ## Patterns @@ -74,6 +78,10 @@ if __name__ == "__main__": - `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): diff --git a/README.rst b/README.rst index 6de6ca5..2853de2 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ the console by applying color to specific patterns. It offers a flexible way to define patterns and apply different text colors, background colors, styles, and underlines to matching text in the output. -In Version 1.4 can strikethrough +In Version 1.4.1 can strikethrough, blink text and italic text Installation ------------ @@ -32,16 +32,19 @@ Use ``start_color()`` for initialize the color print, and 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]) + start_color([pattern1, pattern2, pattern3, email, strike, italic,blink]) # Use the custom print function with colorization - print('Colorpattern v1.4') + print('Colorpattern v1.4.1') 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() @@ -49,8 +52,10 @@ Use ``start_color()`` for initialize the color print, and # Now, printing returns to normal print('-----------------------') - print('Colorpattern v1.4') + print('Colorpattern v1.4.1') 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) @@ -67,7 +72,7 @@ Use ``start_color()`` for initialize the color print, and print("\nNORMAL PRINT AGAIN") # Now, printing returns to normal even with the new patterns print('-----------------------') - print('This is a normal message again.') + print('This is a normal message again. 12345') if __name__ == "__main__": main() @@ -80,6 +85,9 @@ Patterns - ``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): ------------------ diff --git a/colorpattern/__pycache__/colorpattern.cpython-310.pyc b/colorpattern/__pycache__/colorpattern.cpython-310.pyc index 2a16cda..28c9d46 100644 Binary files a/colorpattern/__pycache__/colorpattern.cpython-310.pyc and b/colorpattern/__pycache__/colorpattern.cpython-310.pyc differ diff --git a/colorpattern/colorpattern.py b/colorpattern/colorpattern.py index 32284a6..cfc865e 100644 --- a/colorpattern/colorpattern.py +++ b/colorpattern/colorpattern.py @@ -1,29 +1,69 @@ +""" +This file is (or part of) COLORPATTERN v1.4.1 +Copyright 2023- Croketillo https://github.com/croketillo + +DESCIPTION: +Effortless console text colorization based on user-defined patterns in Python. + + LICENSE - GNU GPL-3 + +This software is protected by the GNU General Public License version 3 (GNU GPL-3). +You are free to use, modify, and redistribute this software in accordance with the +terms of the GNU GPL-3. You can find a copy of the license at the following link: +https://www.gnu.org/licenses/gpl-3.0.html. + +This software is provided as-is, without any warranties, whether express or implied. +Under no circumstances shall the authors or copyright holders be liable for any claims, +damages, or liabilities arising in connection with the use of this software. +If you make modifications to this software and redistribute it, you must comply with +the terms of the GNU GPL-3, which includes the obligation to provide the source code +for your modifications. Additionally, any derived software must also be under the +GNU GPL-3. + +For more information about the GNU GPL-3 and its terms, please carefully read the full +license or visit https://www.gnu.org/licenses/gpl-3.0.html +""" + import re -from colorama import Fore, Style, Back import builtins +from colorama import Fore, Style, Back + class SetPattern: - def __init__(self, pattern, color=None, back=None, style=None, underline=False, strikethrough=False): + def __init__(self, pattern, + color=None, + back=None, + style=None, + underline=False, + strikethrough=False, + italic=False, + blink=False): # Compile the regular expression pattern self.pattern = re.compile(pattern) - # Set default values for color, background, style, and underline + # Set default values for color, background, style, underline, + # strikethrough, italic, and blink self.color = color if color is not None else Fore.RESET self.back = back if back is not None else Back.RESET self.style = style if style is not None else Style.RESET_ALL self.underline = underline self.strikethrough = strikethrough + self.italic = italic + self.blink = blink - def colorize_text(self, text, stop=None): - # Apply color, background, style, underline, and strikethrough to matched text - if self.underline and self.strikethrough: - return self.pattern.sub(lambda match: f"{self.style}{self.color}{self.back}\033[4m\033[9m{match.group()}\033[0m{Style.RESET_ALL}", text) - elif self.underline: - return self.pattern.sub(lambda match: f"{self.style}{self.color}{self.back}\033[4m{match.group()}\033[0m{Style.RESET_ALL}", text) - elif self.strikethrough: - return self.pattern.sub(lambda match: f"{self.style}{self.color}{self.back}\033[9m{match.group()}\033[0m{Style.RESET_ALL}", text) - else: - return self.pattern.sub(lambda match: f"{self.style}{self.color}{self.back}{match.group()}{Style.RESET_ALL}", text) + def colorize_text(self, text): + # Apply color, background, style, underline, strikethrough, + # italic, and blink to matched text + format_str = f"{self.style}{self.color}{self.back}" + if self.underline: + format_str += "\033[4m" + if self.strikethrough: + format_str += "\033[9m" + if self.italic: + format_str += "\033[3m" + if self.blink: + format_str += "\033[5m" + return self.pattern.sub(lambda match: f"{format_str}{match.group()}{Style.RESET_ALL}", text) # Function to initialize colorization def start_color(patterns): diff --git a/dist/colorpattern-1.4.1-py3-none-any.whl b/dist/colorpattern-1.4.1-py3-none-any.whl new file mode 100644 index 0000000..44fd470 Binary files /dev/null and b/dist/colorpattern-1.4.1-py3-none-any.whl differ diff --git a/dist/colorpattern-1.4.1.tar.gz b/dist/colorpattern-1.4.1.tar.gz new file mode 100644 index 0000000..ca3f551 Binary files /dev/null and b/dist/colorpattern-1.4.1.tar.gz differ diff --git a/setup.py b/setup.py index d7d7bdd..c169bb7 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,7 @@ def read(file_name=None, is_encoding=True, ignore_raises=False): setup( name='colorpattern', - version='1.4.0', + version='1.4.1', author='croketillo', author_email='croketillo@gmail.com', license=read("LICENSE", is_encoding=False, ignore_raises=True), @@ -105,6 +105,7 @@ def read(file_name=None, is_encoding=True, ignore_raises=False): 'Topic :: Terminals', # Relacionado con la manipulación de terminales y consolas 'Topic :: Software Development :: Libraries :: Python Modules', # Relacionado con desarrollo de software 'Topic :: Utilities', # Utilidades generales + 'Topic :: Terminals' ], keywords='color pattern console', entry_points={ diff --git a/test/colorpattern_test.py b/test/colorpattern_test.py index 0bfcc62..d195ddb 100644 --- a/test/colorpattern_test.py +++ b/test/colorpattern_test.py @@ -7,16 +7,19 @@ def main(): 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]) + start_color([pattern1, pattern2, pattern3, email, strike, italic,blink]) # Use the custom print function with colorization - print('Colorpattern v1.4') + print('Colorpattern v1.4.1') 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() @@ -24,8 +27,10 @@ def main(): # Now, printing returns to normal print('-----------------------') - print('Colorpattern v1.4') + print('Colorpattern v1.4.1') 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) @@ -42,7 +47,7 @@ def main(): print("\nNORMAL PRINT AGAIN") # Now, printing returns to normal even with the new patterns print('-----------------------') - print('This is a normal message again.') + print('This is a normal message again. 12345') if __name__ == "__main__": main()