mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 12:43:16 +00:00
3f62ce9c19
* Remove log, stderrlog, structopt * Add argh
56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
#[allow(dead_code)]
|
|
mod util;
|
|
|
|
use crate::util::event::{Event, Events};
|
|
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,
|
|
};
|
|
|
|
fn main() -> Result<(), Box<dyn 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 {
|
|
terminal.draw(|mut f| {
|
|
let chunks = Layout::default()
|
|
.direction(Direction::Vertical)
|
|
.constraints(
|
|
[
|
|
Constraint::Percentage(10),
|
|
Constraint::Percentage(80),
|
|
Constraint::Percentage(10),
|
|
]
|
|
.as_ref(),
|
|
)
|
|
.split(f.size());
|
|
|
|
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]);
|
|
})?;
|
|
|
|
match events.next()? {
|
|
Event::Input(input) => {
|
|
if let Key::Char('q') = input {
|
|
break;
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|