2018-09-23 18:59:51 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
mod util;
|
2018-04-01 15:57:26 +00:00
|
|
|
|
2019-01-06 11:57:06 +00:00
|
|
|
use crate::util::event::{Event, Events};
|
2020-03-13 01:02:51 +00:00
|
|
|
use std::{error::Error, io};
|
|
|
|
use termion::{event::Key, input::MouseTerminal, raw::IntoRawMode, screen::AlternateScreen};
|
|
|
|
use tui::{
|
|
|
|
backend::TermionBackend,
|
|
|
|
layout::{Constraint, Direction, Layout},
|
|
|
|
widgets::{Block, Borders},
|
|
|
|
Terminal,
|
|
|
|
};
|
2018-09-23 18:59:51 +00:00
|
|
|
|
2020-03-13 01:02:51 +00:00
|
|
|
fn main() -> Result<(), Box<dyn 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
|
|
|
|
2019-12-15 20:38:18 +00:00
|
|
|
let block = Block::default().title("Block").borders(Borders::ALL);
|
|
|
|
f.render_widget(block, chunks[0]);
|
|
|
|
let block = Block::default().title("Block 2").borders(Borders::ALL);
|
|
|
|
f.render_widget(block, chunks[2]);
|
2018-09-23 18:59:51 +00:00
|
|
|
})?;
|
|
|
|
|
2020-05-16 22:51:57 +00:00
|
|
|
if let Event::Input(input) = events.next()? {
|
|
|
|
if let Key::Char('q') = input {
|
|
|
|
break;
|
2018-12-07 15:17:33 +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
|
|
|
}
|