Render Module

class ConsoleM.Style.render.Render(content: str | None = None)[source]

Bases: object

Handles the conversion of markup syntax into ANSI escape codes and emojis.

This class processes: - Color and style markup: [red], [bold], etc. - Emoji shortcuts: :smile:, :heart:, etc. - Reset markers: [/] or [reset]

The class uses regular expressions to process markup: - Color/style pattern: [(.+?)] - Matches text between square brackets - Emoji pattern: :([^ ]+?): - Matches text between colons

Example

>>> render = Render("[red]Hello[/]")
>>> print(render.render())  # Prints "Hello" in red
>>> render = Render(":smile: Hello :heart:")
>>> print(render.render())  # Prints "😊 Hello ❤️"
__init__(content: str | None = None)[source]

Initialize a Render instance.

Parameters:

content (Optional[str]) – Initial content to render

render(content: str | None = None)[source]

Render the content by converting markup to ANSI escape codes and emojis.

This method processes: - Color and style markup: [red], [bold], etc. - Emoji shortcuts: :smile:, :heart:, etc. - Reset markers: [/] or [reset]

Parameters:

content (Optional[str]) – Content to render. If None, uses the content from initialization.

Returns:

The rendered text with ANSI escape codes and emojis

Return type:

str

ansi_builder(content: str) str[source]

Build ANSI escape codes from style markup.

This method processes color and style combinations: - Single colors: [red] - Single styles: [bold] - Combined styles: [red bold]

Parameters:

content (str) – Style markup to process

Returns:

ANSI escape code sequence

Return type:

str

emoji_render(content: str) str[source]

Convert emoji shortcuts to actual emoji characters.

Parameters:

content (str) – Text containing emoji shortcuts

Returns:

Text with emoji shortcuts replaced by actual emojis

Return type:

str