use fast_rich::layout::Layout;
use fast_rich::prelude::*;
fn run(console: &Console) {
console.rule("[bold green]Panels & Layout Demo[/]");
console.newline();
console.print("[bold]1. Panel Variations[/]");
let p1 = Panel::new("Simple Panel").title("Title");
let p2 = Panel::new(fast_rich::markup::parse(
"Panel with [blue]styled[/] content and [bold]subtitle[/]",
))
.title("Styled")
.subtitle("Footer")
.border_style(BorderStyle::Double)
.padding(2, 1);
let p3 = Panel::new("Fit-to-content Panel")
.title("Compact")
.expand(false)
.border_style(BorderStyle::Rounded)
.style(Style::new().foreground(Color::Cyan));
console.print_renderable(&p1);
console.print_renderable(&p2);
console.print_renderable(&p3);
console.newline();
console.print("[bold]2. Layout (Splits)[/]");
let mut root = Layout::new();
root.split_row(vec![
Layout::new().with_name("Left").with_name("Left"),
Layout::new().with_name("Right").with_name("Right"),
]);
let mut left = Layout::new();
left.update(Panel::new("Left Column\nRow 1\nRow 2"));
let mut right = Layout::new();
right.update(Panel::new("Right Column\nOnly 1 Row"));
console.print("[dim]Note: Layout engine is WIP, stacking panels:[/]");
console.print_renderable(&Panel::new("Top Section"));
#[cfg(feature = "std")]
{
}
console.print_renderable(&left);
console.print_renderable(&right);
console.rule("[bold green]End Panel Demo[/]");
}
fn main() {
let console = Console::new().force_color(true);
run(&console);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_panel_layout_output() {
let console = Console::capture();
run(&console);
let output = console.get_captured_output();
assert!(output.contains("Panels & Layout Demo"));
assert!(output.contains("Simple Panel"));
assert!(output.contains("Styled"));
assert!(output.contains("Footer"));
assert!(output.contains("Left Column"));
assert!(output.contains("Right Column"));
assert!(output.contains("End Panel Demo"));
}
}