2018-09-23 18:59:51 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
mod util;
|
2016-10-15 22:38:20 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
use std::io;
|
|
|
|
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};
|
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, Widget};
|
2018-06-09 09:02:37 +00:00
|
|
|
use tui::Terminal;
|
2016-10-15 22:38:20 +00:00
|
|
|
|
2019-01-06 11:57:06 +00:00
|
|
|
use crate::util::event::{Event, Events};
|
2017-05-08 19:34:41 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
fn main() -> Result<(), failure::Error> {
|
|
|
|
// Terminal initialization
|
|
|
|
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()?;
|
|
|
|
|
|
|
|
// Setup event handlers
|
|
|
|
let events = Events::new();
|
|
|
|
|
|
|
|
loop {
|
|
|
|
terminal.draw(|mut f| {
|
|
|
|
// Wrapping block for a group
|
|
|
|
// Just draw the block and the group on the same area and build the group
|
|
|
|
// with at least a margin of 1
|
2018-12-07 14:43:05 +00:00
|
|
|
let size = f.size();
|
2018-09-23 18:59:51 +00:00
|
|
|
Block::default().borders(Borders::ALL).render(&mut f, size);
|
2018-08-12 17:44:52 +00:00
|
|
|
let chunks = Layout::default()
|
2018-09-23 18:59:51 +00:00
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(4)
|
2018-08-12 17:44:52 +00:00
|
|
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
2018-12-07 14:43:05 +00:00
|
|
|
.split(f.size());
|
2018-09-23 18:59:51 +00:00
|
|
|
{
|
|
|
|
let chunks = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
|
|
|
.split(chunks[0]);
|
|
|
|
Block::default()
|
|
|
|
.title("With background")
|
|
|
|
.title_style(Style::default().fg(Color::Yellow))
|
|
|
|
.style(Style::default().bg(Color::Green))
|
|
|
|
.render(&mut f, chunks[0]);
|
|
|
|
Block::default()
|
|
|
|
.title("Styled title")
|
|
|
|
.title_style(
|
|
|
|
Style::default()
|
|
|
|
.fg(Color::White)
|
|
|
|
.bg(Color::Red)
|
2019-02-25 14:15:00 +00:00
|
|
|
.modifier(Modifier::BOLD),
|
2018-12-07 15:17:33 +00:00
|
|
|
)
|
|
|
|
.render(&mut f, chunks[1]);
|
2018-09-23 18:59:51 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let chunks = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
|
|
|
.split(chunks[1]);
|
|
|
|
Block::default()
|
|
|
|
.title("With borders")
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.render(&mut f, chunks[0]);
|
|
|
|
Block::default()
|
|
|
|
.title("With styled borders")
|
|
|
|
.border_style(Style::default().fg(Color::Cyan))
|
|
|
|
.borders(Borders::LEFT | Borders::RIGHT)
|
|
|
|
.render(&mut f, chunks[1]);
|
|
|
|
}
|
|
|
|
})?;
|
|
|
|
|
|
|
|
match events.next()? {
|
2018-12-07 15:17:33 +00:00
|
|
|
Event::Input(key) => {
|
|
|
|
if key == Key::Char('q') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 18:59:51 +00:00
|
|
|
_ => {}
|
2018-08-12 17:44:52 +00:00
|
|
|
}
|
2018-09-23 18:59:51 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
2016-10-15 22:38:20 +00:00
|
|
|
}
|