mirror of
https://github.com/fdehau/tui-rs.git
synced 2024-11-15 06:12:49 +00:00
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
extern crate rustbox;
|
|
extern crate tui;
|
|
|
|
use std::error::Error;
|
|
use rustbox::Key;
|
|
|
|
use tui::Terminal;
|
|
use tui::backend::RustboxBackend;
|
|
use tui::widgets::{Block, Borders, Paragraph, Widget};
|
|
use tui::layout::{Direction, Group, Size};
|
|
use tui::style::{Color, Modifier, Style};
|
|
|
|
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) {
|
|
Ok(rustbox::Event::KeyEvent(key)) => if key == Key::Char('q') {
|
|
break;
|
|
},
|
|
Err(e) => panic!("{}", e.description()),
|
|
_ => {}
|
|
};
|
|
draw(&mut terminal);
|
|
}
|
|
terminal.show_cursor().unwrap();
|
|
}
|
|
|
|
fn draw(t: &mut Terminal<RustboxBackend>) {
|
|
let size = t.size().unwrap();
|
|
|
|
Group::default()
|
|
.direction(Direction::Vertical)
|
|
.sizes(&[Size::Percent(100)])
|
|
.render(t, &size, |t, chunks| {
|
|
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)),
|
|
)
|
|
.text("It {yellow works}!")
|
|
.render(t, &chunks[0]);
|
|
});
|
|
|
|
t.draw().unwrap();
|
|
}
|