diff --git a/src/index/mod.rs b/src/index/mod.rs index 97958be..2ad17c7 100644 --- a/src/index/mod.rs +++ b/src/index/mod.rs @@ -17,6 +17,7 @@ pub trait IndexView : View { fn get(&self, key: &Key) -> Self::Item; + // todo: AreaIterator enum to switch between Allocated and Procedural area fn area(&self) -> Option> { None } diff --git a/src/main.rs b/src/main.rs index dbe96f7..032d4d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,28 +33,6 @@ use { } }; -struct TermLabel(String); -impl ImplIndexView for TermLabel { - type Key = Point2; - type Value = Option; - - fn get(&self, pos: &Point2) -> Option { - if pos.y == 5 { - Some(TerminalAtom::from(self.0.chars().nth(pos.x as usize)?)) - } else { - None - } - } - - fn area(&self) -> Option>> { - Some( - GridWindowIterator::from( - Point2::new(0, 5) .. Point2::new(self.0.chars().count() as i16, 6) - ).collect() - ) - } -} - //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> #[async_std::main] @@ -77,7 +55,6 @@ async fn main() { let window_size_port = ViewPort::new(); let window_size = SingletonBuffer::new(Vector2::new(0, 0), window_size_port.inner()); - //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> // string editor let edit_port = ViewPort::::new(); @@ -103,7 +80,6 @@ async fn main() { edit_o.write().unwrap().set_offset(Vector2::new(40, 4)); - //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> // stupid label animation let label_port = ViewPort::::new(); @@ -133,7 +109,6 @@ async fn main() { let vec_seq_port = ViewPort::new(); let vec_seq = sequence::VecSequence::new(vec_seq_port.inner()); vec_port.add_observer(vec_seq.clone()); - let vec_term_view = vec_seq_port.outer() .to_index() .map_key( @@ -163,12 +138,10 @@ async fn main() { TerminalEvent::Input(Event::Key(Key::Home)) => editor.goto(0), TerminalEvent::Input(Event::Key(Key::End)) => editor.goto_end(), TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {}, - TerminalEvent::Input(Event::Key(Key::Char(c))) => {editor.insert(c); vec_buf.push(c); }, + TerminalEvent::Input(Event::Key(Key::Char(c))) => editor.insert(c), TerminalEvent::Input(Event::Key(Key::Delete)) => editor.delete(), TerminalEvent::Input(Event::Key(Key::Backspace)) => { editor.prev(); editor.delete(); }, - TerminalEvent::Input(Event::Key(Key::Ctrl('c'))) => { - break - } + TerminalEvent::Input(Event::Key(Key::Ctrl('c'))) => break, _ => {} } } @@ -183,7 +156,6 @@ async fn main() { } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - struct Checkerboard; impl ImplIndexView for Checkerboard { type Key = Point2; @@ -209,7 +181,29 @@ impl ImplIndexView for Checkerboard { } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> +struct TermLabel(String); +impl ImplIndexView for TermLabel { + type Key = Point2; + type Value = Option; + fn get(&self, pos: &Point2) -> Option { + if pos.y == 5 { + Some(TerminalAtom::from(self.0.chars().nth(pos.x as usize)?)) + } else { + None + } + } + + fn area(&self) -> Option>> { + Some( + GridWindowIterator::from( + Point2::new(0, 5) .. Point2::new(self.0.chars().count() as i16, 6) + ).collect() + ) + } +} + +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> struct ScrambleBackground; impl ImplIndexView for ScrambleBackground { type Key = Point2; @@ -225,7 +219,6 @@ impl ImplIndexView for ScrambleBackground { fn area(&self) -> Option>> { None - //Some(Point2::new(0,0) .. Point2::new(50,30)) } } diff --git a/src/terminal/compositor.rs b/src/terminal/compositor.rs index 95045da..05d63b9 100644 --- a/src/terminal/compositor.rs +++ b/src/terminal/compositor.rs @@ -24,24 +24,25 @@ impl Observer for CompositeLayer { let comp = self.comp.upgrade().unwrap(); let mut c = comp.write().unwrap(); - { - let old_view = c.layers[&self.idx].1.clone(); - c.layers.get_mut(&self.idx).unwrap().1 = view.clone(); + let mut v = &mut c.layers.get_mut(&self.idx).unwrap().1; + let old_view = v.clone(); + *v = view.clone(); + drop(v); - if let Some(old_view) = old_view { - if let Some(area) = old_view.area() { - c.cast.notify_each(area); - } - } + //todo: fixme: why does this cause a deadlock? + //c.update_range(); - if let Some(view) = view.as_ref() { - if let Some(area) = view.area() { - c.cast.notify_each(area); - } + if let Some(old_view) = old_view { + if let Some(area) = old_view.area() { + c.cast.notify_each(area); } } - c.update_range(); + if let Some(view) = view.as_ref() { + if let Some(area) = view.area() { + c.cast.notify_each(area); + } + } } fn notify(&self, pos: &Point2) { @@ -131,7 +132,7 @@ impl TerminalCompositor { TerminalCompositeView { idx_count: 0, layers: HashMap::new(), - area: Some(Vec::new()), + area: None,//Some(Vec::new()), cast: port.get_broadcast() } ));