Panels & Rules¶
Panels and rules help organize and visually separate content in your terminal output.
Panels¶
Panels wrap content in a decorative border with an optional title.
Basic Panel¶
use fast_rich::prelude::*;
fn main() {
let console = Console::new();
let panel = Panel::new(Text::plain("Hello, World!"));
console.print_renderable(&panel);
}
Output:
╭────────────────────────────────────────────────────────────────╮
│ Hello, World! │
╰────────────────────────────────────────────────────────────────╯
Panel with Title¶
let panel = Panel::new(Text::plain("Content goes here"))
.title("My Title");
console.print_renderable(&panel);
Output:
╭── My Title ────────────────────────────────────────────────────╮
│ Content goes here │
╰────────────────────────────────────────────────────────────────╯
Styled Panels¶
Apply colors to panel borders:
let panel = Panel::new(fast_rich::markup::parse("[bold]Important info[/]"))
.title("Notice")
.border_style(BorderStyle::Rounded)
.style(Style::new().foreground(Color::Blue));
console.print_renderable(&panel);
Border Styles¶
Panels support the same border styles as tables:
Rules¶
Rules are horizontal lines that can be used as dividers:
Basic Rule¶
Output:
Rule with Title¶
Output:
Styled Rules¶
The title can include any markup:
Combining Panels and Content¶
Panels can contain any Renderable:
Panel with Table¶
let mut table = Table::new();
table.add_column("Key");
table.add_column("Value");
table.add_row_strs(&["Name", "Fast-Rich"]);
table.add_row_strs(&["Version", "0.2.0"]);
let panel = Panel::new(table)
.title("Package Info")
.border_style(BorderStyle::Rounded);
console.print_renderable(&panel);
Multi-line Content¶
let content = "Line 1\nLine 2\nLine 3";
let panel = Panel::new(Text::plain(content));
console.print_renderable(&panel);
Real Terminal Output¶
Command:
Output:
───────────────────────── Panel Demo ─────────────────────────
1. Basic Panel
╭────────────────────────────────────────────────────────────╮
│ This is a simple panel with no title. │
╰────────────────────────────────────────────────────────────╯
2. Panel with Title
╭── My Panel ────────────────────────────────────────────────╮
│ Content inside a titled panel. │
╰────────────────────────────────────────────────────────────╯
3. Styled Panel
╭── Important ───────────────────────────────────────────────╮
│ This panel has a blue border! │
╰────────────────────────────────────────────────────────────╯
Tips¶
Use Panels for Emphasis
Wrap important information in panels to make it stand out: