Text Stylingο
- class ConsoleM.Style.text.Text(content: str)[source]ο
Bases:
objectA 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:
- property contentο
Get or set the rendered content of the text.
The content is cached after first rendering for better performance.
- 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)