2016-11-07 23:35:46 +00:00
|
|
|
extern crate tui;
|
|
|
|
extern crate termion;
|
|
|
|
|
|
|
|
use std::io;
|
|
|
|
use termion::event;
|
|
|
|
use termion::input::TermRead;
|
|
|
|
|
2016-11-28 08:52:51 +00:00
|
|
|
use tui::Terminal;
|
|
|
|
use tui::backend::TermionBackend;
|
2016-11-07 23:35:46 +00:00
|
|
|
use tui::widgets::{Widget, Block, Paragraph};
|
2017-05-08 19:34:41 +00:00
|
|
|
use tui::layout::{Group, Direction, Size, Rect};
|
2016-11-07 23:35:46 +00:00
|
|
|
use tui::style::{Style, Color};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut terminal = Terminal::new(TermionBackend::new().unwrap()).unwrap();
|
|
|
|
let stdin = io::stdin();
|
|
|
|
terminal.clear().unwrap();
|
|
|
|
terminal.hide_cursor().unwrap();
|
2017-05-08 19:34:41 +00:00
|
|
|
|
|
|
|
let mut term_size = terminal.size().unwrap();
|
|
|
|
draw(&mut terminal, &term_size);
|
|
|
|
|
2016-11-07 23:35:46 +00:00
|
|
|
for c in stdin.keys() {
|
2017-05-08 19:34:41 +00:00
|
|
|
let size = terminal.size().unwrap();
|
|
|
|
if size != term_size {
|
|
|
|
terminal.resize(size).unwrap();
|
|
|
|
term_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw(&mut terminal, &term_size);
|
2016-11-07 23:35:46 +00:00
|
|
|
let evt = c.unwrap();
|
|
|
|
if evt == event::Key::Char('q') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
terminal.show_cursor().unwrap();
|
|
|
|
}
|
|
|
|
|
2017-05-08 19:34:41 +00:00
|
|
|
fn draw(t: &mut Terminal<TermionBackend>, size: &Rect) {
|
2016-11-07 23:35:46 +00:00
|
|
|
|
|
|
|
Block::default()
|
|
|
|
.style(Style::default().bg(Color::White))
|
2017-05-21 09:13:24 +00:00
|
|
|
.render(t, size);
|
2016-11-07 23:35:46 +00:00
|
|
|
|
|
|
|
Group::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(5)
|
|
|
|
.sizes(&[Size::Percent(100)])
|
2017-05-21 09:13:24 +00:00
|
|
|
.render(t, size, |t, chunks| {
|
2016-11-07 23:35:46 +00:00
|
|
|
Group::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.sizes(&[Size::Percent(100)])
|
|
|
|
.render(t, &chunks[0], |t, chunks| {
|
|
|
|
Paragraph::default()
|
|
|
|
.text("This is a line\n{fg=red This is a line}\n{bg=red This is a \
|
|
|
|
line}\n{mod=italic This is a line}\n{mod=bold This is a \
|
|
|
|
line}\n{mod=crossed_out This is a line}\n{mod=invert This is a \
|
|
|
|
line}\n{mod=underline This is a \
|
|
|
|
line}\n{bg=green;fg=yellow;mod=italic This is a line}\n")
|
|
|
|
.render(t, &chunks[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
t.draw().unwrap();
|
|
|
|
}
|