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
|
|
|
})?;
|
|
|
|
|
|
|
|
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
|
|
|
}
|