use { std::sync::{Arc, RwLock}, cgmath::Vector2, crate::{ view::{View, Observer}, port::{ViewPort, InnerViewPort, OuterViewPort}, terminal::{TerminalAtom} } }; pub struct TerminalCompositor { layers: Arc, Value = TerminalAtom>>>>>, port: Arc, TerminalAtom>> } impl TerminalCompositor { pub fn new(port: InnerViewPort, TerminalAtom>) -> Self { let layers = Arc::new(RwLock::new(Vec::, Value = TerminalAtom>>>::new())); port.set_view_fn({ let layers = layers.clone(); move |pos| { let mut atom = None; for l in layers.read().unwrap().iter() { match (atom, l.view(pos)) { (None, next) => atom = next, (Some(last), Some(next)) => atom = Some(next.add_style_back(last.style)), _ => {} } } atom } }); TerminalCompositor { layers, port: Arc::new(port) } } pub fn push(&mut self, v: OuterViewPort, TerminalAtom>) { self.layers.write().unwrap().push(v.add_observer(self.port.clone())); } pub fn make_port(&mut self) -> InnerViewPort, TerminalAtom> { let port = ViewPort::new(); self.push(port.outer()); port.inner() } }