From 50fef0fb26e6e6461dd591266bfdae0235e05705 Mon Sep 17 00:00:00 2001 From: Karoline Pauls Date: Sat, 24 Nov 2018 18:42:28 +0000 Subject: [PATCH] Fix rustbox example --- examples/rustbox.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/examples/rustbox.rs b/examples/rustbox.rs index 4044521e..6d6e0640 100644 --- a/examples/rustbox.rs +++ b/examples/rustbox.rs @@ -5,17 +5,16 @@ use rustbox::Key; use std::error::Error; use tui::backend::RustboxBackend; -use tui::layout::{Constraint, Direction, Layout}; use tui::style::{Color, Modifier, Style}; -use tui::widgets::{Block, Borders, Paragraph, Widget}; +use tui::widgets::{Block, Borders, Paragraph, Text, Widget}; use tui::Terminal; -fn main() { +fn main() -> Result<(), failure::Error> { let mut terminal = Terminal::new(RustboxBackend::new().unwrap()).unwrap(); terminal.clear().unwrap(); terminal.hide_cursor().unwrap(); - draw(&mut terminal); loop { + draw(&mut terminal)?; match terminal.backend().rustbox().poll_event(false) { Ok(rustbox::Event::KeyEvent(key)) => if key == Key::Char('q') { break; @@ -23,25 +22,25 @@ fn main() { Err(e) => panic!("{}", e.description()), _ => {} }; - draw(&mut terminal); } - terminal.show_cursor().unwrap(); + terminal.show_cursor()?; + Ok(()) } -fn draw(t: &mut Terminal) { - let size = t.size().unwrap(); - { - let mut f = t.get_frame(); - Paragraph::default() +fn draw(t: &mut Terminal) -> Result<(), std::io::Error> { + let size = t.size()?; + let text = [ + Text::raw("It "), + Text::styled("works", Style::default().fg(Color::Yellow)), + ]; + t.draw(|mut f| { + Paragraph::new(text.iter()) .block( Block::default() .title("Rustbox backend") .title_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold)) .borders(Borders::ALL) .border_style(Style::default().fg(Color::Magenta)), - ).text("It {yellow works}!") - .render(&mut f, &size); - } - - t.draw().unwrap(); + ).render(&mut f, size) + }) }