Prints-charming

Latest version: v1.2.0

Safety actively analyzes 682457 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

1.25

cp.print_var(f"Value: var USD", balance, 'orange', 'vgreen')

Define custom styles and variables for automatic coloring/styling
This dictionary can also be passed during instance creation as an optional parameter
colorprinter_variables = {
"vgreen": ["Confirmed!", "Connected", "Loaded", "Monitor", "ABOVE THRESHOLD", "wss://advanced-trade-ws.coinbase.com", "Starting"],
"vred": ["Failed!", "Error", "Failed", "None", "Skipping.", "Canceling", "Canceled"],
"blue": ["CoinbaseWebsocketClient", "server"],
"yellow": ["1", "returned",],
"vyellow": ["File modified:", "File modified AGAIN", "subscribed"],
"magenta": ["within 10 seconds."],
"cyan": ["|", ""],
"orange": ["New Message!"],
Uncomment the next line to hide API keys or sensitive information
"conceal": [os.environ[key] for key in os.environ if "API" in key],
}

Add custom variables from the dictionary to the ColorPrinter instance
cp.add_variables_from_dict(colorprinter_variables)

Demonstration of automatic styling based on defined variables
var1 = ""
cp.print(f"printing things and some of it will be colored the color or style defined in the dictionary. If it's Confirmed! it will be vgreen. New Message will not be colored, but New Message! will be colored orange! The number 1 will be yellow. The pound sign, {var1} will be styled/colored cyan")

Adding a single variable for styling
cp.add_variable("some text", style_name="vcyan")
cp.print(f"part of me is styled vcyan. Some of this some text will be vcyan.")

Adding another single variable for styling.
Also specifying that the text that hasn't been added to the cp instance be printed in the color, "vgreen".
var2 = "Failed to connect"
cp.add_variable(var2, style_name="red")
cp.print(f"{var2} to some server", color="vgreen")

Adding yet another single variable for styling
cp.add_variable("more text", style_name="green")
cp.print(f"some of this will be green. Less text, more text other text.")

Using Dictionary with print_variables method
vars_and_styles_dict = {
"balance" : (1000, "green"),
"username": ("John", "blue")
}
cp.print_variables(vars_and_styles_dict, "Hello {username}, your balance is {balance} USD.", text_style="yellow")

Using Lists with print_variables method
vars_and_styles_list = ([1000, "John"], ["green", "blue"])
cp.print_variables(vars_and_styles_list, "Hello var2, your balance is var1 USD.", text_style="yellow")


Here's another simple example of creating an instance with colorprinter_variables and your own defined TextStyle styles:

python
Import the ColorPrinter and TextStyle classes from the colorprinter module
from prints_charming import ColorPrinter, TextStyle

colorprinter_variables = {
"vgreen": ["Confirmed!", "Connected", "Loaded", "Monitor", "ABOVE THRESHOLD", "wss://advanced-trade-ws.coinbase.com", "Starting"],
"vred": ["Failed!", "Error", "Failed", "None", "Skipping.", "Canceling", "Canceled"],
"blue": ["CoinbaseWebsocketClient", "server"],
"yellow": ["1", "returned",],
"vyellow": ["File modified:", "File modified AGAIN", "subscribed"],
"magenta": ["within 10 seconds."],
"cyan": ["|", ""],
"orange": ["New Message!"],
"purple": ["My background is purple and my foreground is gray because the purple style reversed option is set to True"]
Uncomment the next line to hide API keys or sensitive information
"conceal": [os.environ[key] for key in os.environ if "API" in key],
}

styles = {
"default" : TextStyle(),
"vgreen" : TextStyle(color="vgreen", bold=True, italic=True, underlined=True, overlined=True, strikethrough=True, blink=True),
"red" : TextStyle(color="red"),
"vred" : TextStyle(color="vred"),
"blue" : TextStyle(color="blue"),
"yellow" : TextStyle(color="yellow"),
"vyellow" : TextStyle(color="vyellow"),
"magenta" : TextStyle(color="magenta", bold=True),
"vmagenta" : TextStyle(color="vmagenta"),
"pink" : TextStyle(color="pink"),
"purple" : TextStyle(color="purple", bg_color="gray", reversed=True),
"cyan" : TextStyle(color="cyan"),
"vcyan" : TextStyle(color="vcyan"),
"orange" : TextStyle(color="orange"),
"gray" : TextStyle(color="gray"),
"header_text" : TextStyle(color="white", bg_color="purple", bold=True),
"header_symbol": TextStyle(color="magenta", bold=True, overlined=True, strikethrough=True),
"task" : TextStyle(color="blue", bold=True),
"conceal" : TextStyle(conceal=True),
}


Create an instance of the ColorPrinter class with colorprinter_variables and styles dictionaries
cp = ColorPrinter(colorprinter_variables=colorprinter_variables, styles=styles)

Demonstration of automatic styling based on defined variables and styles
cp.print(f"My background is purple and my foreground is gray because the purple style reversed option is set to True and that phrase is in the colorprinter_variables dictionary that was added to this ColorPrinter instance. All the additional text will use default bg_color and orange text as specified in this cp.print statement", color="orange")


Here's a logging example:

python

import logging
from prints_charming import ColorPrinter
from datetime import datetime
import time

class ColorPrinterLogHandler(logging.Handler):
TIMESTAMP_FORMAT = '%Y-%m-%d %H:%M:%S.%f'

def __init__(self):
super().__init__()
self.cp = ColorPrinter()

def emit(self, record):
log_entry = self.format(record)
self.handle_log_event(log_entry, log_level=record.levelname)

def handle_log_event(self, text, log_level):
timestamp = time.time()
formatted_timestamp = datetime.fromtimestamp(timestamp).strftime(self.TIMESTAMP_FORMAT)

color = 'blue' default color
if 'ERROR' in log_level.upper():
color = 'red'
elif 'WARNING' in log_level.upper():
color = 'yellow'
elif 'INFO' in log_level.upper():
color = 'green'

timestamped_message = f"LOG[{log_level}]: {formatted_timestamp} {text}"
self.cp.print(timestamped_message, color=color)

Set up logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

Add custom handler to the logger
handler = ColorPrinterLogHandler()
logger.addHandler(handler)

Test logging
logger.info('This is an info message.')
logger.warning('This is a warning message.')
logger.error('This is an error message.')


Here's another logging example for more fine-grained control of individual components:

python

import logging
from prints_charming import ColorPrinter
from datetime import datetime
import time

class ColorPrinterLogHandler(logging.Handler):
TIMESTAMP_FORMAT = '%Y-%m-%d %H:%M:%S.%f'

def __init__(self):
super().__init__()
self.cp = ColorPrinter()

def emit(self, record):
log_entry = self.format(record)
self.handle_log_event(log_entry, log_level=record.levelname)

def handle_log_event(self, text, log_level):
timestamp = time.time()
formatted_timestamp = datetime.fromtimestamp(timestamp).strftime(self.TIMESTAMP_FORMAT)

Define styles for different components
timestamp_style = 'gray' Change as needed
level_styles = {
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'DEBUG': 'blue',
'CRITICAL': 'vred'
}

log_level_style = level_styles.get(log_level, 'default')

Get styled components
styled_timestamp = self.cp.apply_style(timestamp_style, f"LOG[{log_level}]")
styled_level = self.cp.apply_style(log_level_style, log_level)
styled_text = self.cp.apply_style(log_level_style, text)

Create the final styled message
timestamped_message = f"{styled_timestamp}: {formatted_timestamp} {styled_level} - {styled_text}"

print(timestamped_message)


Initialize logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

Create an instance of your custom logging handler
handler = ColorPrinterLogHandler()

Add the custom handler to the logger
logger.addHandler(handler)

Test out different log levels
logger.debug("This is a debug message.")
logger.info("This is an info message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.critical("This is a critical message.")


📧 Contact
For bugs, feature requests, and suggestions, please open an issue on GitHub.

1.2.0

🎉 prints_charming: The Ultimate Terminal Text Coloring and Styling Solution 🎉

![Project Illustration](./images/prints_charming_illustration.png)


🚀 Introduction

Announcing the third public release of **prints_charming**! Initially created in March of 2023, this Python package has become an indispensable part of my development workflow. It has seen extensive use in 100+ of my own Python modules across various private projects I have been working on over the last eight months. "prints_charming" is more than just another color printing library; it's crafted to elevate your development experience by providing a swift and streamlined way to color and style terminal outputs—be it for standard printing, logging, debugging, or tracing—all without becoming an obstruction in your development process. While the library serves as a robust tool for making terminal outputs more readable, visually appealing, and informative, its true power lies in its versatility—enhancing the entire terminal and programming experience.

âś… Current State

For my current needs, this package does everything I require. It's particularly useful for developers who deal with extensive terminal outputs and need to quickly distinguish between different types of information. It's production-ready and has been rigorously tested in various internal projects.

đź›  Future Enhancements

Though **prints_charming** is replete with features tailored for Linux terminals, the fairy tale isn't over, and the door is always open for additional community-driven enhancements. While my current commitments across multiple projects may limit my immediate involvement in further development, your contributions could add new chapters to the prints_charming story.

🌟 Key Features

- **No Dependencies**: Works with the standard Python libraries
- **Efficiency by Design**: With prints_charming, styling your terminal outputs is as simple as adding a keyword argument. Spend less time fiddling with string concatenation and more time writing great code.
- **Text Styling**: Apply foreground and background colors, bold, italic, underlined, and more to your text.
- **Flexible and Customizable**: Use predefined styles or define your own.
- **Variable, Word, Phrase, and substring Styling**: Automatically apply styles to specific variables, words, substrings or phrases in your text.
- **Box/Panel Printing with FormattedTextBox**: Create beautiful Bordered Boxes for sectioning your outputs.
- -**Tablel Printing with TableManager**: Create beautiful Tables inside Boxes or on their own.
- **Intelligent Defaults**: Comes with sensible defaults but allows you to tweak every aspect to your liking.
- **Built for Linux**: This module is developed on Linux for use in Linux terminals, but also supports legacy windows cmd prompt if you set the autoconf_win parameter to True in the init method of PrintsCharming or the WinUtils class, and it supports newer versions of windows os out of the box.

🚀 Quick Start

To get started, install the package and add it to your project.

Option 1: Using pip

bash
pip install prints_charming


Option 2: Cloning from GitHub

Alternatively, you can clone the repository directly from GitHub to access the latest features and updates that might not yet be published on PyPI:

1. Open a terminal window.

2. Navigate to the directory where you want to clone the repository.

3. Run the following command to clone the repository:

bash
git clone https://github.com/deefifofun/prints_charming.git


4. Navigate into the cloned directory:

bash
cd prints_charming


5. Install the package using:

bash
pip install .


This will install the package from the source code.


Here are examples of the basics. Please check out main.py in the examples folder for more

- **show_colors module**: run python -m prints_charming.show_colors for an interactive way to select and name your own colors for the color_map.



python



from prints_charming import (
TextStyle,
PrintsCharming,
PrintsCharmingLogHandler,
TableManager,
FormattedTextBox,
PrintsCharmingError,
set_custom_excepthook
)

import os
import sys
import logging




printscharming_variables = {
"vgreen": ["Hello, world!", "string", "Connected", "Loaded", "Monitor", "ABOVE THRESHOLD", "wss://advanced-trade-ws.coinbase.com", "Starting", "True", "C++", "substring"],
"green": ["apple"],
"vred": ["Error", "Failed", "None", "Skipping.", "Canceling", "Canceled", "Hobbies", "Skills", "False"],
"blue": ["CoinbaseWebsocketClient", "server", "Python"],
"yellow": ["1", "returned", "Flask", "Some",],
"vyellow": ["File modified:", "File modified AGAIN", "subscribed", "=", "JavaScript"],
"magenta": ["within 10 seconds.", "how", "React"],
"cyan": ["|", "", "are", "your", "Project Management System"],
"orange": ["New Message!", "Prints", "Software Developer", "Prince Charming"],
"purple": ["My color is purple", "Reading"],
Uncomment the next line to hide API keys or sensitive information
"conceal": [os.environ[key] for key in os.environ if "API" in key],
}

Create an instance of the PrintsCharming class with default settings, but add printscharming_variables
pc = PrintsCharming(printscharming_variables=printscharming_variables)
pc.print(" Basic printing with ColorPrinter will print in the default style with default color.")
pc.print("Hello, world!")
pc.print(" Print in the default style reverse foreground and background.")
pc.print("Hello, world!", reverse=True)
pc.print(" Specify only the color of the args.")
pc.print("Hello, world!", color="red", dim=True)
pc.print(" Specify only italic and underline will print in the default color.")
pc.print("Hello, world!", italic=True, underline=True)
pc.print(" Specify a predefined style 'magenta'. The 'magenta' style is defined above.")
pc.print("Hello, world!", style="magenta")
pc.print(" Specify predefined style 'task' for printing. The 'task' style is defined above.")
pc.print("This is a task.", style="task")
pc.print(" Specify predefined style 'task' for printing but change color to green and underline to True.")
pc.print("This is a task.", style="task", color="green", underline=True)
pc.print("Show text with bg_color:")
pc.print("This has a bg_color", style="bg_color_green")
pc.print(" Show that 'Hello, world!' isn't color or style defined.")
pc.print("Hello, world!")
print()



python



from prints_charming import (
TextStyle,
PrintsCharming,
PrintsCharmingLogHandler,
TableManager,
FormattedTextBox,
PrintsCharmingError,
set_custom_excepthook
)

import os
import sys
import logging

pc = PrintsCharming()

pc.print(" Use the add_variable method to add 'Hello, world!' to the phrases dictionary with 'vgreen' style.")
pc.add_variable("Hello, world!", style_name="vgreen")
pc.print(" Show that 'Hello, world!' is style defined in the phrases dictionary.")
pc.print("Hello, world!")
pc.print(" Use the remove_variable method to remove 'Hello, world!' from the styled phrases dictionary.")
pc.remove_variable("Hello, world!")
pc.print(" Show that 'Hello, world!' has been removed from the styled phrases dictionary.")
pc.print("Hello, world!")
pc.print(" Define a variable.")
text = "Hello, world!"
pc.print(f" Use the add_variable method to add {text} to the phrases dictionary with 'yellow' style.")
pc.add_variable(text, style_name="yellow")
pc.print(" Show that 'Hello, world!' is style defined in the phrases dictionary.")
pc.print(text)
pc.print(" Show that 'Hello, world!' retains its style while other words are unstyled.")
pc.print(f"This sentence says, {text}")
pc.print(" Show how you can style other words alongside, 'Hello, world!'.")
pc.print(f"This sentence says, {text}", style='task')
pc.print(" Show how the order of the words doesn't matter.")
pc.print(f"{text} Let me say that again, {text} {text} I said it again!", style="orange")
pc.print(" Use the remove_variable method to remove 'Hello, world!' from the styled phrases dictionary.")
pc.remove_variable("Hello, world!")
pc.print(" Show that 'Hello, world!' has been removed from the styled phrases dictionary.")
pc.print("Hello, world!")
print()



python



from prints_charming import (
TextStyle,
PrintsCharming,
PrintsCharmingLogHandler,
TableManager,
FormattedTextBox,
PrintsCharmingError,
set_custom_excepthook
)

import os
import sys
import logging

def setup_logger(pc):
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
handler = PrintsCharmingLogHandler(pc)
logger.addHandler(handler)
return logger

def play_around_with_logging():

pc = PrintsCharming()

my_logger = setup_logger(pc)

init_message = f"PrintsCharmingLogHandler initialized with configuration:\n{pc.print_dict(pc.config)}"
my_logger.debug(init_message)

apply_style = lambda a, b: pc.apply_logging_style(a, b)

my_logger.debug("Debug message with argument 1: {} and argument 2: {}", apply_style('class_name', 'arg1'), apply_style('method_name', 'arg2'))

my_logger.debug("Debugging information.")
my_logger.info("General info.")
my_logger.warning("Warning message.")
my_logger.error("Error encountered.")
my_logger.critical("Critical issue.")
print()

pc.config['internal_logging'] = True
pc.update_logging()


pc.debug(f"PrintsCharming enabled internal logging:\n{pc.print_dict(pc.config)}")



def main():
set_custom_excepthook()


play_around_with_logging()



if __name__ == "__main__":
main()





📧 Contact
For bugs, feature requests, and suggestions, please open an issue on GitHub.

1.1.0

![Project Illustration](https://github.com/deefifofun/prints_charming/blob/master/images/prints_charming_illustration.png)
I couldn't get chatGPT to spell Python correctly and include all the other important details lol had to settle for this after accepting it wasn't going to happen after 68 images.

🚀 Re-release

This release is a re-publication of the original v1.1.0 release that was initially published on October 23, 2023. This re-release maintains the same content and functionality as the original.

🚀 Introduction

"prints_charming" is more than just another color printing library; it's crafted to elevate your development experience by providing a swift and streamlined way to color and style terminal outputs—be it for standard printing, logging, or debugging—all without becoming an obstruction in your development process. While the library serves as a robust tool for making terminal outputs more readable, visually appealing, and informative, its true power lies in its versatility—enhancing the entire terminal and programming experience.

Building on the solid foundation of v1.0.0, this release brings significant updates to improve usability and documentation. While the core functionalities remain, I've made a few key changes to streamline your experience with prints_charming.

âś… Current State

For my current needs, this package does everything I require. It's particularly useful for developers who deal with extensive terminal outputs and need to quickly distinguish between different types of information. It's production-ready and has been rigorously tested in various internal projects.

⚠️ Breaking Changes

Removed print_var and print_variable methods. Their functionalities have been integrated into the print method.

đź›  Major Changes

Removed print_var and print_variable methods and added their functionality to the print method.

🔍 Minor Changes

Updated README.md with more usage examples.
Added an examples directory within the package, including a comprehensive main.py example.

đź›  Future Enhancements

Though **prints_charming** is replete with features tailored for Linux terminals, the fairy tale isn't over, and the door is always open for additional community-driven enhancements. While my current commitments across multiple projects may limit my immediate involvement in further development, your contributions could add new chapters to the prints_charming story. For those interested in broadening the library's reach, I welcome contributions that extend support to Windows Command Prompt and PowerShell, as this is currently outside the scope of my planned updates.

🌟 Key Features

- **No Dependencies**: Works with the standard Python libraries
- **Efficiency by Design**: With prints_charming, styling your terminal outputs is as simple as adding a keyword argument. Spend less time fiddling with string concatenation and more time writing great code.
- **Rich Text Styling**: Apply foreground and background colors, bold, italic, underlined, and more to your text.
- **Flexible and Customizable**: Use predefined styles or define your own.
- **Variable, Word, and Phrase Styling**: Automatically apply styles to specific variables, words, or phrases in your text.
- **Header Printing**: Create beautiful headers for sectioning your outputs.
- **Intelligent Defaults**: Comes with sensible defaults but allows you to tweak every aspect to your liking.
- **Built for Linux**: This module is developed and tested on Linux and is intended for use in Linux terminals.

🚀 Quick Start

To get started, install the package and add it to your project.

Option 1: Using pip

bash
pip install prints_charming


Option 2: Cloning from GitHub

Alternatively, you can clone the repository directly from GitHub to access the latest features and updates that might not yet be published on PyPI:

1. Open a terminal window.

2. Navigate to the directory where you want to clone the repository.

3. Run the following command to clone the repository:

bash
git clone https://github.com/deefifofun/prints_charming.git


4. Navigate into the cloned directory:

bash
cd prints_charming


5. Install the package using:

bash
pip install .


This will install the package from the source code.

Here are examples of pretty much everything:

python
from prints_charming import TextStyle, ColorPrinter

config = {
"color_text" : True,
"args_to_strings" : True,
"style_names" : True,
"style_words_by_index": True,
"kwargs" : True,
"conceal" : True,
"width" : 80,
}

styles = {
"default" : TextStyle(),
"white" : TextStyle(color="white"),
"gray" : TextStyle(color="gray"),
"green" : TextStyle(color="green"),
"vgreen" : TextStyle(color="vgreen"),
"red" : TextStyle(color="red"),
"vred" : TextStyle(color="vred", bold=True, italic=True, underlined=True, overlined=True, blink=True),
"blue" : TextStyle(color="blue"),
"vblue" : TextStyle(color="vblue"),
"yellow" : TextStyle(color="yellow"),
"vyellow" : TextStyle(color="vyellow"),
"cyan" : TextStyle(color="cyan"),
"vcyan" : TextStyle(color="vcyan"),
"magenta" : TextStyle(color="magenta", bold=True, underlined=True),
"pink" : TextStyle(color="pink"),
"purple" : TextStyle(color="purple", bg_color="gray", reversed=True),
"orange" : TextStyle(color="orange"),
"header_text" : TextStyle(color="white", bg_color="purple", bold=True, reversed=True),
"header_symbol": TextStyle(color="magenta", bold=True, overlined=True, strikethrough=True),
"task" : TextStyle(color="blue", bold=True),
"conceal" : TextStyle(conceal=True),
}

colorprinter_variables = {
"vgreen": ["Hello, world!", "Connected", "Loaded", "Monitor", "ABOVE THRESHOLD", "wss://advanced-trade-ws.coinbase.com", "Starting", "True"],
"vred": ["Failed!", "Error", "Failed", "None", "Skipping.", "Canceling", "Canceled"],
"blue": ["CoinbaseWebsocketClient", "server"],
"yellow": ["1", "returned",],
"vyellow": ["File modified:", "File modified AGAIN", "subscribed"],
"magenta": ["within 10 seconds."],
"cyan": ["|", ""],
"orange": ["New Message!"],
"purple": ["My background is purple"]
Uncomment the next line to hide API keys or sensitive information
"conceal": [os.environ[key] for key in os.environ if "API" in key],
}

Create an instance of the ColorPrinter class with default colormap, custom config, and custom styles
cp = ColorPrinter(config=config, styles=styles)

Print all the foreground colors in the color map with it's name to the right of it.
You can optionally supply your own color_map as an arg in the init method.
For styling of the first cp.print statement we will add 'Name:' to the word map.
cp.print("", color="yellow")
cp.print(" Print all the foreground colors in the color map each with it's name to the right of it.", color="yellow")
cp.print(" You can optionally supply your own color_map as an arg in the init method.", color="yellow")
cp.print(" For styling of the first cp.print statement we will add 'Name:' to the word map.", color="yellow")
cp.print("", color="yellow")
cp.add_variable("Name:", style_name="default")
for color_name, color_code in cp.color_map.items():
cp.print(f" This is one of the prints_charming foreground colors in the color map. Name: {color_name}", color=color_name)

Print all the styles in the styles dictionary with it's name to the right of it.
As you can see most of the styles are named after the foreground color, but you can edit the styles and name them whatever you want!
You can optionally supply your own styles dictionary as an arg in the init method as I have done here, but if you don't this is also the default.
cp.print("", color="yellow")
cp.print(" Print all the styles in the styles dictionary each with it's name to the right of it.", color="yellow")
cp.print(" As you can see most of the styles in this example are named after the foreground color.", color="yellow")
cp.print(" You can optionally supply your own styles dictionary or not and go with the default.", color="yellow")
cp.print(" You can edit the styles and name them whatever you want!", color="yellow")
cp.print("", color="yellow")
for style_name, style in cp.styles.items():
cp.print(f" This is one of the prints_charming above defined styles! Name: {style_name}", style=style_name)

Print all the computed background colors from the color map dictionary.
cp.print("", color="yellow")
cp.print(" Print all the computed background colors from the color map dictionary.", color="yellow")
cp.print("", color="yellow")
for color in cp.color_map:
cp.print_bg(color, length=80)

Basic printing with ColorPrinter will print in the default style with default color.
cp.print(" Basic printing with ColorPrinter will print in the default style with default color.")
cp.print("Hello, world!")

Print in the default style reversed foreground and background.
cp.print(" Print in the default style reversed foreground and background.")
cp.print("Hello, world!", reversed=True)

Specify only the color of the args.
cp.print(" Specify only the color of the args.")
cp.print("Hello, world!", color="red")

Specify only italic and underlined will print in the default color.
cp.print(" Specify only italic and underlined will print in the default color.")
cp.print("Hello, world!", italic=True, underlined=True)

Specify a predefined style 'magenta'. The 'magenta' style is defined above.
cp.print(" Specify a predefined style 'magenta'. The 'magenta' style is defined above.")
cp.print("Hello, world!", style="magenta")

Specify predefined style 'task' for printing. The 'task' style is defined above.
cp.print(" Specify predefined style 'task' for printing. The 'task' style is defined above.")
cp.print("This is a task.", style="task")

Specify predefined style 'task' for printing. But change color to green and underlined to True.
cp.print(" Specify predefined style 'task' for printing. But change color to green and underlined to True.")
cp.print("This is a task.", style ="task", color="green", underlined=True)

Show that 'Hello, world!' isn't color or style defined.
cp.print(" Show that 'Hello, world!' isn't color or style defined.")
cp.print("Hello, world!")

Use the add_variable method to add 'Hello, world!' to the phrases dictionary with 'vgreen' style.
cp.print(" Use the add_variable method to add 'Hello, world!' to the phrases dictionary with 'vgreen' style.")
cp.add_variable("Hello, world!", style_name="vgreen")

Show that 'Hello, world!' is style defined in the phrases dictionary.
cp.print(" Show that 'Hello, world!' is style defined in the phrases dictionary.")
cp.print("Hello, world!")

Use the remove_variable method to remove 'Hello, world!' from the styled phrases dictionary.
cp.print(" Use the remove_variable method to remove 'Hello, world!' from the styled phrases dictionary.")
cp.remove_variable("Hello, world!")

Show that 'Hello, world!' has been removed from the styled phrases dictionary.
cp.print(" Show that 'Hello, world!' has been removed from the styled phrases dictionary.")
cp.print("Hello, world!")

Define a variable.
cp.print(" Define a variable.")
text = "Hello, world!"

Use the add_variable method to add {text} to the phrases dictionary with 'yellow' style.
cp.print(" Use the add_variable method to add {text} to the phrases dictionary with 'yellow' style.")
cp.add_variable(text, style_name="yellow")

Show that 'Hello, world!' is style defined in the phrases dictionary.
cp.print(" Show that 'Hello, world!' is style defined in the phrases dictionary.")
cp.print(text)

Show that 'Hello, world!' retains it's style while other words are unstyled.
cp.print(" Show that 'Hello, world!' retains it's style while other words are unstyled.")
cp.print(f"This sentence says, {text}")

Show how you can style other words alongside, 'Hello, world!'.
cp.print(" Show how you can style other words alongside, 'Hello, world!'.")
cp.print(f"This sentence says, {text}", style='task')

Show how the order of the words doesn't matter.
cp.print(" Show how the order of the words doesn't matter.")
cp.print(f"{text} Let me say that again, {text} {text} I said it again!", style="orange")

Use the remove_variable method to remove 'Hello, world!' from the styled phrases dictionary.
cp.print(" Use the remove_variable method to remove 'Hello, world!' from the styled phrases dictionary.")
cp.remove_variable("Hello, world!")

Show that 'Hello, world!' has been removed from the styled phrases dictionary.
cp.print(" Show that 'Hello, world!' has been removed from the styled phrases dictionary.")
cp.print("Hello, world!")

Show how to style words by index.
cp.print(" Show how to style words by index.")
cp.print(f"These words are going to be styled by their indexes",
style={0:"vgreen", (1,4):"blue", (4,6):"yellow", 6:"purple", (7,10):"pink"})

Printing styled variables in the middle of a string with text substitution without having to add the variable to the cp instance.
cp.print(" Printing styled variables in the middle of a string with text substitution without having to add the variable to the cp instance.")
'var' in text is subbed with the value of balance.
cp.print(" 'var' in text is subbed with the value of balance.")

1.0.0

🚀 Re-release

This release is a re-publication of the original v1.0.0 release that was initially published on October 18th, 2023. This re-release maintains the same content and functionality as the original.

🚀 Introduction

Announcing the first public release of **prints_charming**! Initially created in March of this year, this Python package has become an indispensable part of my development workflow. It has seen extensive use in 100+ of my own Python modules across various private projects I have been working on over the last eight months. "prints_charming" is more than just another color printing library; it's crafted to elevate your development experience by providing a swift and streamlined way to color and style terminal outputs—be it for standard printing, logging, debugging, or tracing—all without becoming an obstruction in your development process. While the library serves as a robust tool for making terminal outputs more readable, visually appealing, and informative, its true power lies in its versatility—enhancing the entire terminal and programming experience.

âś… Current State

For my current needs, this package does everything I require. It's particularly useful for developers who deal with extensive terminal outputs and need to quickly distinguish between different types of information. It's production-ready and has been rigorously tested in various internal projects.

đź›  Future Enhancements

Though **prints_charming** is replete with features tailored for Linux terminals, the door is always open for additional community-driven enhancements. While my current commitments across multiple projects may limit my immediate involvement in further development, your contributions can play a pivotal role in expanding this package's capabilities. For those interested in broadening the library's reach, I welcome contributions that extend support to Windows Command Prompt and PowerShell, as this is currently outside the scope of my planned updates.

🌟 Key Features

- **Efficiency by Design**: With prints_charming, styling your terminal outputs is as simple as adding a keyword argument. Spend less time fiddling with string concatenation and more time writing great code.
- **Rich Text Styling**: Apply foreground and background colors, bold, italic, underlined, and more to your text.
- **Flexible and Customizable**: Use predefined styles or define your own.
- **Variable, Word, and Phrase Styling**: Automatically apply styles to specific variables, words, or phrases in your text.
- **Header Printing**: Create beautiful headers for sectioning your outputs.
- **Intelligent Defaults**: Comes with sensible defaults but allows you to tweak every aspect to your liking.
- **Built for Linux**: This module is developed and tested on Linux and is intended for use in Linux terminals.

🚀 Quick Start

To get started, install the package and add it to your project.

Here's a simple example:

python
Import the ColorPrinter class from the prints_charming module
from prints_charming import ColorPrinter

Create an instance of the ColorPrinter class
cp = ColorPrinter()

Basic printing with ColorPrinter
'vgreen' specifies a very bright green color
cp.print("Hello, world!", color="vgreen")

Using a predefined style called 'task' for printing
cp.print("This is a task.", style="task")

Using variable printing; 'orange' for text and 'vgreen' for the variable value

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.