Text Styling

class ConsoleM.Style.text.Text(content: str)[source]

Bases: object

A powerful interface for creating styled terminal output using markup syntax.

The Text class allows you to create styled text using markup syntax: - Colors: [red]text[/], [blue]text[/], etc. - Styles: [bold]text[/], [underline]text[/], etc. - Emojis: :emoji_name: - Reset: [reset] to clear all styling

Available Colors:

[red], [blue], [green], [yellow], [magenta], [cyan], [white], [black], [gray], [default]

Available Styles:

[bold] or [b], [dim] or [d], [italic] or [i], [underline] or [u], [blink], [blink2], [reverse] or [r], [conceal] or [c], [strike] or [s], [underline2] or [uu], [frame], [encircle], [overline] or [o]

Example

>>> Text("[red]Error:[/] Something went wrong").print()
>>> Text("[bold blue]Important:[/] This is a message").print()
>>> Text("[green]Success![/] :check_mark: Operation completed").print()
__init__(content: str)[source]

Initialize a Text object for styled terminal output.

Parameters:

content (str) – The text content with optional styling markup

Examples

>>> Text("[red]Hello[/] World").print()
Hello World  # "Hello" will be red
>>> Text("[blue bold]Styled[/] :smile: text").print()
Styled 😊 text  # "Styled" will be blue and bold
property raw_content

Get the raw content before rendering.

Returns:

The original text with markup syntax

Return type:

str

property content

Get or set the rendered content of the text.

The content is cached after first rendering for better performance.

Returns:

The rendered text with all styling applied

Return type:

str

Raises:

TypeError – If trying to set content to a non-string value

print(*values: object, sep: str | None = ' ', end: str | None = '\n', file: SupportsWrite[str] | None = None, flush: Literal[False] = False) None[source]

Print the rendered text to the console.

This method wraps Python’s built-in print function and supports all its parameters.

Args:

*values: Additional values to print sep: Separator between values (default: β€œ β€œ) end: String to print at the end (default: β€œ

β€œ)

file: File to write to (default: None, uses sys.stdout) flush: Whether to flush the output (default: False)