2016-11-02 18:17:18 +00:00
|
|
|
extern crate tui;
|
|
|
|
|
2016-11-28 08:52:51 +00:00
|
|
|
use tui::Terminal;
|
2017-09-03 13:34:05 +00:00
|
|
|
use tui::backend::MouseBackend;
|
2016-11-02 18:17:18 +00:00
|
|
|
use tui::widgets::Widget;
|
|
|
|
use tui::buffer::Buffer;
|
|
|
|
use tui::layout::Rect;
|
2016-11-06 20:41:32 +00:00
|
|
|
use tui::style::Style;
|
2016-11-02 18:17:18 +00:00
|
|
|
|
|
|
|
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 draw(&self, area: &Rect, buf: &mut Buffer) {
|
2016-11-06 20:41:32 +00:00
|
|
|
buf.set_string(area.left(), area.top(), self.text, &Style::default());
|
2016-11-02 18:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Label<'a> {
|
|
|
|
fn text(&mut self, text: &'a str) -> &mut Label<'a> {
|
|
|
|
self.text = text;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2017-09-03 13:34:05 +00:00
|
|
|
let mut terminal = Terminal::new(MouseBackend::new().unwrap()).unwrap();
|
2016-11-06 17:49:57 +00:00
|
|
|
let size = terminal.size().unwrap();
|
2016-11-03 22:59:04 +00:00
|
|
|
terminal.clear().unwrap();
|
2016-11-06 17:49:57 +00:00
|
|
|
Label::default().text("Test").render(&mut terminal, &size);
|
2016-11-03 22:59:04 +00:00
|
|
|
terminal.draw().unwrap();
|
2016-11-02 18:17:18 +00:00
|
|
|
}
|