Package: custerm
TerminalThis class provides various utility functions for interacting with the terminal, including options selection and text formatting.Methodsoptions(options_list: list) -> str: Allows the user to select an option from a list of options. Returns the selected option as a string.print(text: str, markdown: bool = False): Prints text to the terminal, optionally formatting it based on Markdown syntax. Markdown formatting includes support for headings, bold, underline, italics, list items, and code blocks.render_markdown(text: str) -> str: Renders text in the Markdown format, applying specific ANSI color codes to the text based on the Markdown syntax.Usagefromcusterm.terminalimportTerminal# Example options usageoptions_list=["Option 1","Option 2","Option 3"]selected_option=Terminal.options(options_list)print(f"Selected option:{selected_option}")# Example text printingTerminal.print("This is a sample text.",markdown=False)# Example Markdown renderingmarkdown_text="### This is a heading\n**Bold text**\n*Italic text*\n- List item 1\n- List item 2\n```python\nprint('Hello, world!')\n```"rendered_text=Terminal.render_markdown(markdown_text)print(rendered_text)ExceptionsInvalidChoiceException: Raised when an invalid option choice is made during the options selection process.InvalidMarkdownException: Raised when the provided Markdown syntax is invalid during the rendering process.Dependenciesdataclasses: Used for creating data classes and defining their attributes.re: Required for handling regular expressions for Markdown formatting.custerm.ansi.Color: A module providing ANSI color codes for text formatting.custerm.exceptions: A module providing custom exceptions for the terminal class.ColorTheColorclass in thecustermlibrary provides ANSI color codes for text formatting and supports custom color definitions.ANSI Color AttributesANSI_RESET: Resets all ANSI formatting.Text Colors:ANSI_BLACK,ANSI_RED,ANSI_GREEN,ANSI_YELLOW,ANSI_BLUE,ANSI_MAGENTA,ANSI_CYAN,ANSI_WHITE: Basic text colors.ANSI_BRIGHT_BLACK,ANSI_BRIGHT_RED,ANSI_BRIGHT_GREEN,ANSI_BRIGHT_YELLOW,ANSI_BRIGHT_BLUE,ANSI_BRIGHT_MAGENTA,ANSI_BRIGHT_CYAN,ANSI_BRIGHT_WHITE: Bright text colors.Background Colors:ANSI_BG_BLACK,ANSI_BG_RED,ANSI_BG_GREEN,ANSI_BG_YELLOW,ANSI_BG_BLUE,ANSI_BG_MAGENTA,ANSI_BG_CYAN,ANSI_BG_WHITE: Basic background colors.ANSI_BG_BRIGHT_BLACK,ANSI_BG_BRIGHT_RED,ANSI_BG_BRIGHT_GREEN,ANSI_BG_BRIGHT_YELLOW,ANSI_BG_BRIGHT_BLUE,ANSI_BG_BRIGHT_MAGENTA,ANSI_BG_BRIGHT_CYAN,ANSI_BG_BRIGHT_WHITE: Bright background colors.Other Attributes:ANSI_DIM_BLACK,ANSI_DIM_RED,ANSI_DIM_GREEN,ANSI_DIM_YELLOW,ANSI_DIM_BLUE,ANSI_DIM_MAGENTA,ANSI_DIM_CYAN,ANSI_DIM_WHITE: Dim text colors.ANSI_LIGHT_BLACK,ANSI_LIGHT_RED,ANSI_LIGHT_GREEN,ANSI_LIGHT_YELLOW,ANSI_LIGHT_BLUE,ANSI_LIGHT_MAGENTA,ANSI_LIGHT_CYAN,ANSI_LIGHT_WHITE: Light text colors.ANSI_BG_DIM_BLACK,ANSI_BG_DIM_RED,ANSI_BG_DIM_GREEN,ANSI_BG_DIM_YELLOW,ANSI_BG_DIM_BLUE,ANSI_BG_DIM_MAGENTA,ANSI_BG_DIM_CYAN,ANSI_BG_DIM_WHITE: Dim background colors.ANSI_BG_LIGHT_BLACK,ANSI_BG_LIGHT_RED,ANSI_BG_LIGHT_GREEN,ANSI_BG_LIGHT_YELLOW,ANSI_BG_LIGHT_BLUE,ANSI_BG_LIGHT_MAGENTA,ANSI_BG_LIGHT_CYAN,ANSI_BG_LIGHT_WHITE: Light background colors.Methodsapply_color_tags(text: str) -> str: Applies ANSI color tags to text based on custom color definitions or predefined ANSI attributes. It parses text for color tags in the format[color]text[/color]and replaces them with the corresponding color codes. The parsed text is returned with ANSI formatting.add_custom_color(color_name: str, color_code: str): Adds a custom color definition to theColorclass. Thecolor_nameis the name of the color in uppercase, andcolor_codeis the ANSI color code to use.remove_custom_color(color_name: str): Removes a custom color definition from theColorclass based on thecolor_name.Usagefromcusterm.ansiimportColor# Apply custom color tagsformatted_text=Color.apply_color_tags("[MYCOLOR]This is colored text[/MYCOLOR]")print(formatted_text)# Add custom color definitionColor.add_custom_color("MYCOLOR","\033[38;5;203m")# Apply custom color tags againformatted_text=Color.apply_color_tags("[MYCOLOR]This is colored text[/MYCOLOR]")print(formatted_text)# Remove custom color definitionColor.remove_custom_color("MYCOLOR")Dependenciesre: Required for handling regular expressions in theapply_color_tagsmethod for parsing color tags.Predefined color attributes, such asANSI_RESET,ANSI_BLACK,ANSI_RED, etc., provide predefined ANSI color codes for various color formatting options.CustomLoggerTheCustomLoggerclass in thecustermlibrary provides a custom logging utility built on top of Python'sloggingmodule. It allows you to configure and use loggers with different log levels.Logger ConfigurationLoggerConfigLoggerConfigis a data class that holds the configuration for the logger:log_level(Optional, Default:logging.DEBUG): The desired logging level for the logger.log_file(Optional, Default:"my_library.log"): The path to the log file where logs will be stored.Log LevelsLogLevelis a data class that defines different log levels that can be used with the logger:DEBUG: Debug log level.INFO: Info log level.WARNING: Warning log level.ERROR: Error log level.SUCCESS: Custom log level with the value25.Methodscreate_logger(cls, config: LoggerConfig) -> CustomLogger: Creates an instance of theCustomLoggerclass based on the providedLoggerConfig.log_debug(self, message: str): Logs a debug message.log_info(self, message: str): Logs an info message.log_warning(self, message: str): Logs a warning message.log_error(self, message: str): Logs an error message.log_success(self, message: str): Logs a success message using the custom log level defined inLogLevel.log(self, message: str, level=logging.INFO): Logs a message with the specified log level. If thelevelis not a valid log level, it defaults toINFOand logs a warning.set_log_level(level): Sets the log level for the logger to the specified level. If the providedlevelis not valid, it uses the default level ofDEBUG.available_log_levels(Property): Returns the available log levels fromLogLevelas a dictionary.Usagefromcusterm.logimportCustomLogger,LoggerConfig# Create a logger with custom configurationconfig=LoggerConfig(log_level=LogLevel.WARNING,log_file="custom.log")logger=CustomLogger.create_logger(config)# Log messages at different levelslogger.log_debug("This is a debug message")logger.log_info("This is an info message")logger.log_warning("This is a warning message")logger.log_error("This is an error message")logger.log_success("This is a success message")# Set the log level dynamicallylogger.set_log_level(LogLevel.DEBUG)# Log a message with the updated log levellogger.log("This is a debug message with the updated log level",level=LogLevel.DEBUG)Dependencieslogging: Required for creating and configuring loggers.Predefined log levels:DEBUG,INFO,WARNING, andERROR, as well as a custom log levelSUCCESS, provide different levels for logging messages.