2018-09-23 18:59:51 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
mod util;
|
2018-04-01 15:57:26 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
use std::io;
|
2018-04-01 15:57:26 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
use termion::event::Key;
|
|
|
|
use termion::input::MouseTerminal;
|
|
|
|
use termion::raw::IntoRawMode;
|
|
|
|
use termion::screen::AlternateScreen;
|
|
|
|
use tui::backend::TermionBackend;
|
2018-11-26 02:06:34 +00:00
|
|
|
use tui::layout::{Constraint, Direction, Layout};
|
2018-05-06 10:59:24 +00:00
|
|
|
use tui::widgets::{Block, Borders, Widget};
|
2018-06-09 09:02:37 +00:00
|
|
|
use tui::Terminal;
|
2018-04-01 15:57:26 +00:00
|
|
|
|
2019-01-06 11:57:06 +00:00
|
|
|
use crate::util::event::{Event, Events};
|
2018-09-23 18:59:51 +00:00
|
|
|
|
|
|
|
fn main() -> Result<(), failure::Error> {
|
2018-04-01 15:57:26 +00:00
|
|
|
// Terminal initialization
|
2018-09-23 18:59:51 +00:00
|
|
|
let stdout = io::stdout().into_raw_mode()?;
|
|
|
|
let stdout = MouseTerminal::from(stdout);
|
|
|
|
let stdout = AlternateScreen::from(stdout);
|
|
|
|
let backend = TermionBackend::new(stdout);
|
|
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
terminal.hide_cursor()?;
|
2018-04-01 15:57:26 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
let events = Events::new();
|
2018-04-01 15:57:26 +00:00
|
|
|
|
|
|
|
loop {
|
2018-09-23 18:59:51 +00:00
|
|
|
terminal.draw(|mut f| {
|
|
|
|
let chunks = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.constraints(
|
|
|
|
[
|
|
|
|
Constraint::Percentage(10),
|
|
|
|
Constraint::Percentage(80),
|
|
|
|
Constraint::Percentage(10),
|
|
|
|
]
|
2018-12-07 15:17:33 +00:00
|
|
|
.as_ref(),
|
|
|
|
)
|
2018-12-07 14:43:05 +00:00
|
|
|
.split(f.size());
|
2018-09-23 18:59:51 +00:00
|
|
|
|
|
|
|
Block::default()
|
|
|
|
.title("Block")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.render(&mut f, chunks[0]);
|
|
|
|
Block::default()
|
|
|
|
.title("Block 2")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.render(&mut f, chunks[2]);
|
|
|
|
})?;
|
|
|
|
|
|
|
|
match events.next()? {
|
2018-12-07 15:17:33 +00:00
|
|
|
Event::Input(input) => {
|
|
|
|
if let Key::Char('q') = input {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 18:59:51 +00:00
|
|
|
_ => {}
|
2018-04-01 15:57:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
Ok(())
|
2018-04-01 15:57:26 +00:00
|
|
|
}
|