lib-nested/src/main.rs

72 lines
1.7 KiB
Rust
Raw Normal View History

2020-12-04 20:38:51 +01:00
#![feature(trait_alias)]
2020-12-08 15:51:24 +01:00
#![feature(assoc_char_funcs)]
2020-12-04 20:38:51 +01:00
pub mod view;
pub mod port;
pub mod channel;
pub mod singleton_buffer;
pub mod vec_buffer;
2020-12-09 12:56:38 +01:00
pub mod terminal;
2020-12-04 20:38:51 +01:00
use {
async_std::{
prelude::*, task, stream
},
std::{
sync::{Arc, RwLock}
},
cgmath::{Vector2},
crate::{
view::{View, Observer},
port::{InnerViewPort, OuterViewPort},
singleton_buffer::SingletonBuffer,
2020-12-09 12:56:38 +01:00
vec_buffer::VecBuffer,
terminal::{Terminal, TerminalAtom, TerminalStyle}
}
};
2020-12-04 20:38:51 +01:00
#[async_std::main]
async fn main() {
2020-12-08 15:51:24 +01:00
let digits = port::ViewPort::new();
let mut buf = VecBuffer::new(digits.inner());
let digit_view = digits.outer()
// digit encoding
.map_value(
|digit|
if let Some(digit) = digit {
2020-12-09 12:56:38 +01:00
Some(TerminalAtom::new(char::from_digit(digit, 16).unwrap(), TerminalStyle::bg_color((100,30,30))))
2020-12-08 15:51:24 +01:00
} else {
None
}
)
// simple horizontal layout
.map_key(
|idx| Vector2::<i16>::new(idx as i16, 0),
|pos| pos.x as usize
);
2020-12-04 20:38:51 +01:00
2020-12-09 12:56:38 +01:00
let fut = task::spawn(Terminal::show(digit_view));
2020-12-04 20:38:51 +01:00
2020-12-09 12:56:38 +01:00
task::sleep(std::time::Duration::from_secs(1)).await;
2020-12-08 15:51:24 +01:00
buf.push(0);
2020-12-09 12:56:38 +01:00
buf.push(10);
task::sleep(std::time::Duration::from_secs(1)).await;
2020-12-08 15:51:24 +01:00
buf.push(2);
buf.push(3);
task::sleep(std::time::Duration::from_secs(1)).await;
2020-12-08 15:51:24 +01:00
buf.push(4);
2020-12-09 12:56:38 +01:00
task::sleep(std::time::Duration::from_secs(1)).await;
buf.insert(0, 15);
task::sleep(std::time::Duration::from_secs(1)).await;
buf.remove(2);
task::sleep(std::time::Duration::from_secs(1)).await;
2020-12-04 20:38:51 +01:00
drop(buf);
2020-12-08 15:51:24 +01:00
drop(digits);
2020-12-04 20:38:51 +01:00
fut.await;
}