mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 20:53:19 +00:00
Fix rustbox example
This commit is contained in:
parent
4c46ef69e9
commit
50fef0fb26
1 changed files with 15 additions and 16 deletions
|
@ -5,17 +5,16 @@ use rustbox::Key;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use tui::backend::RustboxBackend;
|
use tui::backend::RustboxBackend;
|
||||||
use tui::layout::{Constraint, Direction, Layout};
|
|
||||||
use tui::style::{Color, Modifier, Style};
|
use tui::style::{Color, Modifier, Style};
|
||||||
use tui::widgets::{Block, Borders, Paragraph, Widget};
|
use tui::widgets::{Block, Borders, Paragraph, Text, Widget};
|
||||||
use tui::Terminal;
|
use tui::Terminal;
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), failure::Error> {
|
||||||
let mut terminal = Terminal::new(RustboxBackend::new().unwrap()).unwrap();
|
let mut terminal = Terminal::new(RustboxBackend::new().unwrap()).unwrap();
|
||||||
terminal.clear().unwrap();
|
terminal.clear().unwrap();
|
||||||
terminal.hide_cursor().unwrap();
|
terminal.hide_cursor().unwrap();
|
||||||
draw(&mut terminal);
|
|
||||||
loop {
|
loop {
|
||||||
|
draw(&mut terminal)?;
|
||||||
match terminal.backend().rustbox().poll_event(false) {
|
match terminal.backend().rustbox().poll_event(false) {
|
||||||
Ok(rustbox::Event::KeyEvent(key)) => if key == Key::Char('q') {
|
Ok(rustbox::Event::KeyEvent(key)) => if key == Key::Char('q') {
|
||||||
break;
|
break;
|
||||||
|
@ -23,25 +22,25 @@ fn main() {
|
||||||
Err(e) => panic!("{}", e.description()),
|
Err(e) => panic!("{}", e.description()),
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
draw(&mut terminal);
|
|
||||||
}
|
}
|
||||||
terminal.show_cursor().unwrap();
|
terminal.show_cursor()?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(t: &mut Terminal<RustboxBackend>) {
|
fn draw(t: &mut Terminal<RustboxBackend>) -> Result<(), std::io::Error> {
|
||||||
let size = t.size().unwrap();
|
let size = t.size()?;
|
||||||
{
|
let text = [
|
||||||
let mut f = t.get_frame();
|
Text::raw("It "),
|
||||||
Paragraph::default()
|
Text::styled("works", Style::default().fg(Color::Yellow)),
|
||||||
|
];
|
||||||
|
t.draw(|mut f| {
|
||||||
|
Paragraph::new(text.iter())
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.title("Rustbox backend")
|
.title("Rustbox backend")
|
||||||
.title_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold))
|
.title_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold))
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_style(Style::default().fg(Color::Magenta)),
|
.border_style(Style::default().fg(Color::Magenta)),
|
||||||
).text("It {yellow works}!")
|
).render(&mut f, size)
|
||||||
.render(&mut f, &size);
|
})
|
||||||
}
|
|
||||||
|
|
||||||
t.draw().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue