Expand description
Console - the central entry point for styled terminal output.
The Console handles rendering styled content to the terminal,
including color detection, width calculation, and ANSI code generation.
§Examples
§Basic Printing with Markup
ⓘ
use rich_rust::Console;
let console = Console::new();
// Print with markup syntax
console.print("[bold red]Error:[/] Something went wrong");
console.print("[green]Success![/] Operation completed");
// Markup supports colors, attributes, and combinations
console.print("[bold italic #ff8800 on blue]Custom styling[/]");§Console Builder
ⓘ
use rich_rust::console::{Console, ConsoleBuilder};
use rich_rust::color::ColorSystem;
let console = Console::builder()
.color_system(ColorSystem::EightBit) // Force 256 colors
.width(80) // Fixed width
.markup(true) // Enable markup parsing
.build();§Print Options
ⓘ
use rich_rust::console::{Console, PrintOptions};
use rich_rust::style::Style;
use rich_rust::text::JustifyMethod;
let console = Console::new();
let options = PrintOptions::new()
.with_style(Style::new().bold())
.with_justify(JustifyMethod::Center)
.with_markup(true);
console.print_with_options("Centered bold text", &options);§Capturing Output
ⓘ
use rich_rust::Console;
let mut console = Console::new();
// Start capturing
console.begin_capture();
console.print("[bold]Hello[/]");
// Get captured segments
let segments = console.end_capture();
for seg in &segments {
println!("Text: {:?}, Style: {:?}", seg.text, seg.style);
}§Terminal Detection
The Console automatically detects terminal capabilities:
- Color system:
TrueColor(24-bit), 256 colors, or 16 colors - Terminal dimensions: Width and height in character cells
- TTY status: Whether output is to an interactive terminal
You can override these with the builder pattern or by setting explicit values.
Structs§
- Console
- The main Console for rendering styled output.
- Console
Builder - Builder for creating a Console with custom settings.
- Console
Dimensions - Console dimensions in cells.
- Console
Options - Options for rendering.
- Export
Html Options - Options for controlling HTML export.
- Export
SvgOptions - Options for controlling SVG export.
- LogOptions
- Options for controlling log output format.
- Print
Options - Print options for controlling output.
- Theme
Guard - RAII guard returned by
Console::use_theme.
Enums§
- LogLevel
- Log level for
console.log().
Constants§
- CONSOLE_
HTML_ FORMAT - Default HTML export template (Rich 13.9.4).
- CONSOLE_
SVG_ FORMAT - Default SVG export template (Rich 13.9.4).
Traits§
- Render
Hook - Hook for intercepting rendered segments before output.