2018-09-23 18:59:51 +00:00
|
|
|
extern crate failure;
|
2016-11-07 23:35:46 +00:00
|
|
|
extern crate termion;
|
2017-10-30 21:28:37 +00:00
|
|
|
extern crate tui;
|
2016-11-07 23:35:46 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
mod util;
|
|
|
|
|
2016-11-07 23:35:46 +00:00
|
|
|
use std::io;
|
|
|
|
|
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::{Alignment, Constraint, Direction, Layout};
|
2018-08-12 22:27:56 +00:00
|
|
|
use tui::style::{Color, Modifier, Style};
|
|
|
|
use tui::widgets::{Block, Paragraph, Text, Widget};
|
2018-06-09 09:02:37 +00:00
|
|
|
use tui::Terminal;
|
2016-11-07 23:35:46 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
use 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()?;
|
|
|
|
|
|
|
|
let events = Events::new();
|
|
|
|
|
|
|
|
loop {
|
2018-12-07 14:43:05 +00:00
|
|
|
terminal.draw(|mut f| {
|
|
|
|
let size = f.size();
|
2018-09-23 18:59:51 +00:00
|
|
|
|
2018-12-07 14:43:05 +00:00
|
|
|
let mut long_line: String = std::iter::repeat('X').take(size.width.into()).collect();
|
|
|
|
long_line.insert_str(0, "Very long line: ");
|
|
|
|
long_line.push('\n');
|
2018-09-29 21:12:34 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
Block::default()
|
|
|
|
.style(Style::default().bg(Color::White))
|
|
|
|
.render(&mut f, size);
|
|
|
|
|
|
|
|
let chunks = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(5)
|
|
|
|
.constraints(
|
|
|
|
[
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
]
|
2018-12-07 15:17:33 +00:00
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(size);
|
2016-11-07 23:35:46 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
let text = [
|
|
|
|
Text::raw("This a line\n"),
|
|
|
|
Text::styled("This a line\n", Style::default().fg(Color::Red)),
|
|
|
|
Text::styled("This a line\n", Style::default().bg(Color::Blue)),
|
|
|
|
Text::styled(
|
|
|
|
"This a longer line\n",
|
|
|
|
Style::default().modifier(Modifier::CrossedOut),
|
|
|
|
),
|
2018-09-29 21:12:34 +00:00
|
|
|
Text::raw(&long_line),
|
2018-09-23 18:59:51 +00:00
|
|
|
Text::styled(
|
|
|
|
"This a line\n",
|
|
|
|
Style::default().fg(Color::Green).modifier(Modifier::Italic),
|
|
|
|
),
|
|
|
|
];
|
2018-08-12 20:13:32 +00:00
|
|
|
|
2018-09-23 18:59:51 +00:00
|
|
|
Paragraph::new(text.iter())
|
|
|
|
.alignment(Alignment::Left)
|
|
|
|
.render(&mut f, chunks[0]);
|
|
|
|
Paragraph::new(text.iter())
|
|
|
|
.alignment(Alignment::Center)
|
|
|
|
.wrap(true)
|
|
|
|
.render(&mut f, chunks[1]);
|
|
|
|
Paragraph::new(text.iter())
|
|
|
|
.alignment(Alignment::Right)
|
|
|
|
.wrap(true)
|
|
|
|
.render(&mut f, chunks[2]);
|
|
|
|
})?;
|
|
|
|
|
|
|
|
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
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
2016-11-07 23:35:46 +00:00
|
|
|
}
|