use minui::{
widgets::{
Alignment, BorderChars, Container, Label, Panel, TextBlock, TextWrapMode,
VerticalAlignment, Widget,
},
Color, ColorPair, Event, Result, TerminalWindow, Window,
};
fn main() -> Result<()> {
let mut window = TerminalWindow::new()?;
window.set_auto_flush(false);
window.clear_screen()?;
let info_panel = Panel::new(0, 0, 40, 10)
.with_header("Welcome to MinUI")
.with_body("This demo shows different panel styles & features.\n\nPress 'q' to quit.")
.with_header_style(BorderChars::double_line()) .with_header_color(Some(ColorPair::new(Color::Blue, Color::Transparent)))
.with_header_border_color(Color::Blue)
.with_body_style(BorderChars::single_line()) .with_alignment(Alignment::Center)
.with_padding(1);
let info_label =
Label::new(0, 1, "This is a double-line container").with_alignment(Alignment::Center);
let info_container = Container::new(0, 11, 0, 5)
.with_style(BorderChars::double_line())
.with_content(info_label);
let floating_label = Label::new(5, 9, "Floating label, spooky!").with_text_color(Color::Red);
let text_block = TextBlock::new(
0,
0,
40,
5,
"This is supposed to be a really long block of text, \
maybe the description of an item in a game, or some lore \
paragraph. I don't know, do whatever you want :)",
)
.with_colors(ColorPair::new(Color::White, Color::Blue))
.with_wrap_mode(TextWrapMode::WrapWords)
.with_alignment(Alignment::Center, VerticalAlignment::Middle);
let paragraph_container = Container::new(42, 9, 0, 0)
.with_auto_size(true)
.with_style(BorderChars::ascii())
.with_content(text_block);
info_panel.draw(&mut window)?;
info_container.draw(&mut window)?;
floating_label.draw(&mut window)?;
paragraph_container.draw(&mut window)?;
window.flush()?;
loop {
if let Ok(event) = window.get_input() {
if let Event::Character('q') = event {
break;
}
}
}
Ok(())
}