Skip to content

Commit

Permalink
Update version 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
croketillo committed Nov 11, 2023
1 parent cd5bde6 commit bde6d2b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 30 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -25,25 +25,30 @@ 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()
print("\nNORMAL PRINT")
# 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)
Expand All @@ -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
Expand All @@ -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):

Expand Down
20 changes: 14 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -32,25 +32,30 @@ Use ``start_color(<patterns>)`` 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()
print("\nNORMAL PRINT")
# 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)
Expand All @@ -67,7 +72,7 @@ Use ``start_color(<patterns>)`` 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()
Expand All @@ -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):
------------------
Expand Down
Binary file modified colorpattern/__pycache__/colorpattern.cpython-310.pyc
Binary file not shown.
66 changes: 53 additions & 13 deletions colorpattern/colorpattern.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
"""
This file is (or part of) COLORPATTERN v1.4.1
Copyright 2023- Croketillo <croketillo@gmail.com> 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):
Expand Down
Binary file added dist/colorpattern-1.4.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/colorpattern-1.4.1.tar.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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={
Expand Down
13 changes: 9 additions & 4 deletions test/colorpattern_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@ 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()
print("\nNORMAL PRINT")
# 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)
Expand All @@ -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()

0 comments on commit bde6d2b

Please sign in to comment.