PrettyPrint
prettypi.pretty_print module helps you to print easily styled messages.
- Use the StyledStr class to print styled messages.
Color the text.
Set the background color of the text.
Set the style of the text.
Align the text.
- Use the Alert class to print alerts.
Information alert.
Warning alert.
Error alert.
Success alert.
Custom alert.
- class prettypi.pretty_print.Alert(message: str = '', prefix: Emoji | str = Emoji.BULB, surround_prefix: str = ' ,')
Bases:
objectAlert class for creating alert messages
Features:
Use static methods to create different types of alerts (info, warning, error, success).
Use Alert class to create custom alerts with custom emojis.
Customize your messages with other elements present in the pretty_print module.
Surround your prefix with surround_prefix=”left,right” to add more style to your alert.
- Parameters:
message (str) – The message to display in the alert
prefix (Union[Emoji, str]) – The emoji to display before the message
surround_prefix (str) – The string to surround the prefix with, e.g. ,”left,right” (default is “ ,”)
- Raises:
ValueError – If surround_prefix is not of the form “left,right”
Example:
from prettypi.pretty_print import Alert alert = Alert.info("This is an information alert") print(alert)
custom_alert = Alert("This is a warning alert", prefix="+", surround_prefix=" [,]") print(custom_alert)
- static error(message: str = '', surround_prefix: str = ' ,')
Create an error alert
- Parameters:
message (str) – The message to display in the alert
surround_prefix (str) – The string to surround the prefix with, surround_prefix=”left,right”, default is “ ,”
- Returns:
An error alert
- Return type:
- static info(message: str = '', surround_prefix: str = ' ,')
Create an information alert
- Parameters:
message (str) – The message to display in the alert
surround_prefix (str) – The string to surround the prefix with, surround_prefix=”left,right”, default is “ ,”
- Returns:
An information alert
- Return type:
- static success(message: str = '', surround_prefix: str = ' ,')
Create a success alert
- Parameters:
message (str) – The message to display in the alert
surround_prefix (str) – The string to surround the prefix with, surround_prefix=”left,right”, default is “ ,”
- Returns:
An success alert
- Return type:
- static warning(message: str = '', surround_prefix: str = ' ,')
Create a warning alert
- Parameters:
message (str) – The message to display in the alert
surround_prefix (str) – The string to surround the prefix with, surround_prefix=”left,right”, default is “ ,”
- Returns:
An warning alert
- Return type:
- class prettypi.pretty_print.StyledStr(string: str = '', color: Color = Color.RESET, style: Style = Style.RESET, background_color: BackgroundColor = BackgroundColor.RESET)
Bases:
objectThis class represents a string with ANSI color and style codes. You can use this class to create a string with ANSI color and style codes.
Features:
Set the color of the string.
Set the background color of the string.
Set the style of the string.
- Parameters:
string (str) – The string to style
color (Color) – The color of the string, defaults to Color.RESET
style (Style) – The style of the string, defaults to Style.RESET
background_color (BackgroundColor) – The background color of the string, defaults to BackgroundColor.RESET
- Raises:
ValueError – If the input is invalid
Example:
from prettypi.pretty_print import StyledStr from prettypi.utils import Color, Style, Emoji, BackgroundColor print(StyledStr("This is a styled string", color=Color.RED, style=Style.BOLD))
styled_str = StyledStr( "My name", background_color=BackgroundColor.MAGENTA, style=Style.UNDERLINE ) styled_str2 = StyledStr("Toto", color=Color.RED, style=Style.BOLD) print(f"{styled_str} is {styled_str2} {Emoji.SMILE}")
- set_align(align: Align, width: int = None)
Set the alignment of the string.
- Parameters:
align (Align) – The alignment of the string
width (int) – The width of the max string, defaults to None
- Raises:
ValueError – If the input is invalid
Example:
from prettypi.utils import Align styled_str = StyledStr("This is a styled string") styled_str.set_align(Align.CENTER, 20) print(styled_str)
- set_background_color(background_color: Color)
Set the background color of the string.
- Parameters:
background_color (Color) – The background color of the string
- Raises:
ValueError – If the input is invalid
Example:
styled_str = StyledStr("This is a styled string") styled_str.set_background_color(BackgroundColor.RED) print(styled_str)