2016-11-06 17:49:57 +00:00
|
|
|
extern crate rustbox;
|
2017-10-30 21:28:37 +00:00
|
|
|
extern crate tui;
|
2016-11-06 17:49:57 +00:00
|
|
|
|
|
|
|
use rustbox::Key;
|
2018-05-06 10:59:24 +00:00
|
|
|
use std::error::Error;
|
2016-11-06 17:49:57 +00:00
|
|
|
|
2016-11-28 08:52:51 +00:00
|
|
|
use tui::backend::RustboxBackend;
|
2017-10-30 21:28:37 +00:00
|
|
|
use tui::style::{Color, Modifier, Style};
|
2018-11-24 18:42:28 +00:00
|
|
|
use tui::widgets::{Block, Borders, Paragraph, Text, Widget};
|
2018-06-09 09:02:37 +00:00
|
|
|
use tui::Terminal;
|
2016-11-06 17:49:57 +00:00
|
|
|
|
2018-11-24 18:42:28 +00:00
|
|
|
fn main() -> Result<(), failure::Error> {
|
2016-11-06 17:49:57 +00:00
|
|
|
let mut terminal = Terminal::new(RustboxBackend::new().unwrap()).unwrap();
|
|
|
|
terminal.clear().unwrap();
|
|
|
|
terminal.hide_cursor().unwrap();
|
|
|
|
loop {
|
2018-11-24 18:42:28 +00:00
|
|
|
draw(&mut terminal)?;
|
2016-11-06 17:49:57 +00:00
|
|
|
match terminal.backend().rustbox().poll_event(false) {
|
2017-10-30 21:28:37 +00:00
|
|
|
Ok(rustbox::Event::KeyEvent(key)) => if key == Key::Char('q') {
|
|
|
|
break;
|
|
|
|
},
|
2016-11-06 17:49:57 +00:00
|
|
|
Err(e) => panic!("{}", e.description()),
|
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
}
|
2018-11-24 18:42:28 +00:00
|
|
|
terminal.show_cursor()?;
|
|
|
|
Ok(())
|
2016-11-06 17:49:57 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 18:42:28 +00:00
|
|
|
fn draw(t: &mut Terminal<RustboxBackend>) -> 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())
|
2018-08-12 17:44:52 +00:00
|
|
|
.block(
|
|
|
|
Block::default()
|
2018-08-12 22:27:56 +00:00
|
|
|
.title("Rustbox backend")
|
|
|
|
.title_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold))
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(Style::default().fg(Color::Magenta)),
|
2018-11-24 18:42:28 +00:00
|
|
|
).render(&mut f, size)
|
|
|
|
})
|
2016-11-06 17:49:57 +00:00
|
|
|
}
|