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;
|
2018-08-12 17:44:52 +00:00
|
|
|
use tui::layout::{Constraint, Direction, Layout};
|
2017-10-30 21:28:37 +00:00
|
|
|
use tui::style::{Color, Modifier, Style};
|
2018-05-06 10:59:24 +00:00
|
|
|
use tui::widgets::{Block, Borders, Paragraph, Widget};
|
2018-06-09 09:02:37 +00:00
|
|
|
use tui::Terminal;
|
2016-11-06 17:49:57 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut terminal = Terminal::new(RustboxBackend::new().unwrap()).unwrap();
|
|
|
|
terminal.clear().unwrap();
|
|
|
|
terminal.hide_cursor().unwrap();
|
|
|
|
draw(&mut terminal);
|
|
|
|
loop {
|
|
|
|
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()),
|
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
draw(&mut terminal);
|
|
|
|
}
|
|
|
|
terminal.show_cursor().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw(t: &mut Terminal<RustboxBackend>) {
|
|
|
|
let size = t.size().unwrap();
|
2018-08-12 17:44:52 +00:00
|
|
|
{
|
|
|
|
let mut f = t.get_frame();
|
|
|
|
Paragraph::default()
|
|
|
|
.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)),
|
2017-09-11 05:58:37 +00:00
|
|
|
)
|
2018-08-12 17:44:52 +00:00
|
|
|
.text("It {yellow works}!")
|
|
|
|
.render(&mut f, &size);
|
|
|
|
}
|
2016-11-06 17:49:57 +00:00
|
|
|
|
|
|
|
t.draw().unwrap();
|
|
|
|
}
|