mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 20:53:19 +00:00
3f62ce9c19
* Remove log, stderrlog, structopt * Add argh
62 lines
1.5 KiB
Rust
62 lines
1.5 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, buffer::Buffer, layout::Rect, style::Style, widgets::Widget, Terminal,
|
|
};
|
|
|
|
struct Label<'a> {
|
|
text: &'a str,
|
|
}
|
|
|
|
impl<'a> Default for Label<'a> {
|
|
fn default() -> Label<'a> {
|
|
Label { text: "" }
|
|
}
|
|
}
|
|
|
|
impl<'a> Widget for Label<'a> {
|
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
|
buf.set_string(area.left(), area.top(), self.text, Style::default());
|
|
}
|
|
}
|
|
|
|
impl<'a> Label<'a> {
|
|
fn text(mut self, text: &'a str) -> Label<'a> {
|
|
self.text = text;
|
|
self
|
|
}
|
|
}
|
|
|
|
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)?;
|
|
|
|
let events = Events::new();
|
|
|
|
loop {
|
|
terminal.draw(|mut f| {
|
|
let size = f.size();
|
|
let label = Label::default().text("Test");
|
|
f.render_widget(label, size);
|
|
})?;
|
|
|
|
match events.next()? {
|
|
Event::Input(key) => {
|
|
if key == Key::Char('q') {
|
|
break;
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|