lib-nested/examples/tty-01-hello/src/main.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

extern crate cgmath;
2023-11-26 22:09:03 +01:00
extern crate nested;
extern crate nested_tty;
extern crate r3vi;
2023-11-26 22:09:03 +01:00
extern crate termion;
use {
cgmath::Vector2,
2023-11-28 20:52:25 +01:00
nested::repr_tree::Context,
nested_tty::{Terminal, TerminalCompositor, TTYApplication, TerminalEvent, TerminalStyle, TerminalView},
r3vi::view::{port::UpdateTask, ViewPort},
std::sync::{Arc, RwLock},
2023-11-26 22:09:03 +01:00
termion::event::{Event, Key},
};
#[async_std::main]
async fn main() {
/* initialize our terminal
*/
2023-11-28 20:52:25 +01:00
let tty_app = TTYApplication::new(|event| { /* handle event */ });
2023-11-26 22:09:03 +01:00
/* populate the view in `term_port`
*/
2023-11-28 20:52:25 +01:00
let compositor = TerminalCompositor::new(tty_app.port.inner());
2023-11-26 22:09:03 +01:00
compositor
.write()
.unwrap()
.push(nested_tty::make_label("test").offset(Vector2::new(7, 2)));
2023-11-26 22:09:03 +01:00
compositor.write().unwrap().push(
nested_tty::make_label("Hello World")
.map_item(|p, a| {
a.add_style_back(TerminalStyle::fg_color(((25 * p.x % 255) as u8, 200, 0)))
})
.offset(Vector2::new(5, 3)),
);
2023-11-26 22:09:03 +01:00
/* write the changes in the view of `term_port` to the terminal
*/
2023-11-28 20:52:25 +01:00
tty_app.show().await.expect("output error!");
2023-11-26 22:09:03 +01:00
}
2023-11-28 20:52:25 +01:00