From e21b888b6ce3c56cc71d93d55dfcedae9477e8a4 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 19 Apr 2021 05:01:09 +0200 Subject: [PATCH] move nested into a lib crate --- .gitignore | 1 + Cargo.toml | 24 +- nested/Cargo.toml | 17 + {src => nested/src}/cell_layout.rs | 0 {src => nested/src}/core/channel.rs | 0 {src => nested/src}/core/mod.rs | 0 {src => nested/src}/core/observer.rs | 0 {src => nested/src}/core/port.rs | 0 {src => nested/src}/core/view.rs | 0 {src => nested/src}/grid/mod.rs | 0 {src => nested/src}/grid/offset.rs | 0 {src => nested/src}/index/map_item.rs | 0 {src => nested/src}/index/map_key.rs | 0 {src => nested/src}/index/mod.rs | 0 {src => nested/src}/leveled_term_view.rs | 0 nested/src/lib.rs | 5 + {src => nested/src}/projection.rs | 0 {src => nested/src}/sequence/flatten.rs | 0 {src => nested/src}/sequence/mod.rs | 0 {src => nested/src}/sequence/seq2idx.rs | 0 {src => nested/src}/sequence/vec_buffer.rs | 0 {src => nested/src}/singleton/buffer.rs | 0 {src => nested/src}/singleton/mod.rs | 0 {src => nested/src}/string_editor.rs | 0 {src => nested/src}/terminal/atom.rs | 0 {src => nested/src}/terminal/compositor.rs | 0 {src => nested/src}/terminal/mod.rs | 0 {src => nested/src}/terminal/style.rs | 0 {src => nested/src}/terminal/terminal.rs | 0 src/main.rs | 360 --------------------- 30 files changed, 30 insertions(+), 377 deletions(-) create mode 100644 nested/Cargo.toml rename {src => nested/src}/cell_layout.rs (100%) rename {src => nested/src}/core/channel.rs (100%) rename {src => nested/src}/core/mod.rs (100%) rename {src => nested/src}/core/observer.rs (100%) rename {src => nested/src}/core/port.rs (100%) rename {src => nested/src}/core/view.rs (100%) rename {src => nested/src}/grid/mod.rs (100%) rename {src => nested/src}/grid/offset.rs (100%) rename {src => nested/src}/index/map_item.rs (100%) rename {src => nested/src}/index/map_key.rs (100%) rename {src => nested/src}/index/mod.rs (100%) rename {src => nested/src}/leveled_term_view.rs (100%) create mode 100644 nested/src/lib.rs rename {src => nested/src}/projection.rs (100%) rename {src => nested/src}/sequence/flatten.rs (100%) rename {src => nested/src}/sequence/mod.rs (100%) rename {src => nested/src}/sequence/seq2idx.rs (100%) rename {src => nested/src}/sequence/vec_buffer.rs (100%) rename {src => nested/src}/singleton/buffer.rs (100%) rename {src => nested/src}/singleton/mod.rs (100%) rename {src => nested/src}/string_editor.rs (100%) rename {src => nested/src}/terminal/atom.rs (100%) rename {src => nested/src}/terminal/compositor.rs (100%) rename {src => nested/src}/terminal/mod.rs (100%) rename {src => nested/src}/terminal/style.rs (100%) rename {src => nested/src}/terminal/terminal.rs (100%) delete mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore index e2a3069..83827f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +Cargo.lock /target *~ diff --git a/Cargo.toml b/Cargo.toml index d5d3936..41aaf24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,7 @@ - -[package] -authors = ["Michael Sippel "] -edition = "2018" -name = "NeStEd" -version = "0.1.0" - -[dependencies] -no_deadlocks = "*" -cgmath = "0.17.0" -termion = "1.5.5" -signal-hook = "0.3.1" -signal-hook-async-std = "0.2.0" - -[dependencies.async-std] -version = "1.7.0" -features = ["unstable", "attributes"] +[workspace] +members = [ + "nested", + "math/str2int", + "math/int2str", + "math/fib" +] diff --git a/nested/Cargo.toml b/nested/Cargo.toml new file mode 100644 index 0000000..4bd049b --- /dev/null +++ b/nested/Cargo.toml @@ -0,0 +1,17 @@ + +[package] +authors = ["Michael Sippel "] +edition = "2018" +name = "nested" +version = "0.1.0" + +[dependencies] +no_deadlocks = "*" +cgmath = "0.17.0" +termion = "1.5.5" +signal-hook = "0.3.1" +signal-hook-async-std = "0.2.0" + +[dependencies.async-std] +version = "1.7.0" +features = ["unstable", "attributes"] diff --git a/src/cell_layout.rs b/nested/src/cell_layout.rs similarity index 100% rename from src/cell_layout.rs rename to nested/src/cell_layout.rs diff --git a/src/core/channel.rs b/nested/src/core/channel.rs similarity index 100% rename from src/core/channel.rs rename to nested/src/core/channel.rs diff --git a/src/core/mod.rs b/nested/src/core/mod.rs similarity index 100% rename from src/core/mod.rs rename to nested/src/core/mod.rs diff --git a/src/core/observer.rs b/nested/src/core/observer.rs similarity index 100% rename from src/core/observer.rs rename to nested/src/core/observer.rs diff --git a/src/core/port.rs b/nested/src/core/port.rs similarity index 100% rename from src/core/port.rs rename to nested/src/core/port.rs diff --git a/src/core/view.rs b/nested/src/core/view.rs similarity index 100% rename from src/core/view.rs rename to nested/src/core/view.rs diff --git a/src/grid/mod.rs b/nested/src/grid/mod.rs similarity index 100% rename from src/grid/mod.rs rename to nested/src/grid/mod.rs diff --git a/src/grid/offset.rs b/nested/src/grid/offset.rs similarity index 100% rename from src/grid/offset.rs rename to nested/src/grid/offset.rs diff --git a/src/index/map_item.rs b/nested/src/index/map_item.rs similarity index 100% rename from src/index/map_item.rs rename to nested/src/index/map_item.rs diff --git a/src/index/map_key.rs b/nested/src/index/map_key.rs similarity index 100% rename from src/index/map_key.rs rename to nested/src/index/map_key.rs diff --git a/src/index/mod.rs b/nested/src/index/mod.rs similarity index 100% rename from src/index/mod.rs rename to nested/src/index/mod.rs diff --git a/src/leveled_term_view.rs b/nested/src/leveled_term_view.rs similarity index 100% rename from src/leveled_term_view.rs rename to nested/src/leveled_term_view.rs diff --git a/nested/src/lib.rs b/nested/src/lib.rs new file mode 100644 index 0000000..66e9d4e --- /dev/null +++ b/nested/src/lib.rs @@ -0,0 +1,5 @@ + +pub fn magic_header() { + eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>"); +} + diff --git a/src/projection.rs b/nested/src/projection.rs similarity index 100% rename from src/projection.rs rename to nested/src/projection.rs diff --git a/src/sequence/flatten.rs b/nested/src/sequence/flatten.rs similarity index 100% rename from src/sequence/flatten.rs rename to nested/src/sequence/flatten.rs diff --git a/src/sequence/mod.rs b/nested/src/sequence/mod.rs similarity index 100% rename from src/sequence/mod.rs rename to nested/src/sequence/mod.rs diff --git a/src/sequence/seq2idx.rs b/nested/src/sequence/seq2idx.rs similarity index 100% rename from src/sequence/seq2idx.rs rename to nested/src/sequence/seq2idx.rs diff --git a/src/sequence/vec_buffer.rs b/nested/src/sequence/vec_buffer.rs similarity index 100% rename from src/sequence/vec_buffer.rs rename to nested/src/sequence/vec_buffer.rs diff --git a/src/singleton/buffer.rs b/nested/src/singleton/buffer.rs similarity index 100% rename from src/singleton/buffer.rs rename to nested/src/singleton/buffer.rs diff --git a/src/singleton/mod.rs b/nested/src/singleton/mod.rs similarity index 100% rename from src/singleton/mod.rs rename to nested/src/singleton/mod.rs diff --git a/src/string_editor.rs b/nested/src/string_editor.rs similarity index 100% rename from src/string_editor.rs rename to nested/src/string_editor.rs diff --git a/src/terminal/atom.rs b/nested/src/terminal/atom.rs similarity index 100% rename from src/terminal/atom.rs rename to nested/src/terminal/atom.rs diff --git a/src/terminal/compositor.rs b/nested/src/terminal/compositor.rs similarity index 100% rename from src/terminal/compositor.rs rename to nested/src/terminal/compositor.rs diff --git a/src/terminal/mod.rs b/nested/src/terminal/mod.rs similarity index 100% rename from src/terminal/mod.rs rename to nested/src/terminal/mod.rs diff --git a/src/terminal/style.rs b/nested/src/terminal/style.rs similarity index 100% rename from src/terminal/style.rs rename to nested/src/terminal/style.rs diff --git a/src/terminal/terminal.rs b/nested/src/terminal/terminal.rs similarity index 100% rename from src/terminal/terminal.rs rename to nested/src/terminal/terminal.rs diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index b0b40c6..0000000 --- a/src/main.rs +++ /dev/null @@ -1,360 +0,0 @@ -#![feature(trait_alias)] -#![feature(assoc_char_funcs)] - -pub mod core; -pub mod index; -pub mod grid; -pub mod sequence; -pub mod singleton; -pub mod terminal; -pub mod projection; -pub mod string_editor; -pub mod leveled_term_view; -//pub mod cell_layout; - -use { - async_std::{task}, - std::sync::{Arc}, - std::sync::RwLock, - cgmath::{Vector2, Point2}, - termion::event::{Event, Key}, - crate::{ - core::{View, Observer, ObserverExt, ObserverBroadcast, ViewPort, OuterViewPort}, - index::{ImplIndexView}, - terminal::{ - TerminalView, - TerminalAtom, - TerminalStyle, - TerminalEvent, - Terminal, - TerminalCompositor - }, - sequence::{VecBuffer, SequenceView}, - grid::{GridOffset, GridWindowIterator}, - singleton::{SingletonView, SingletonBuffer}, - string_editor::{StringEditor, insert_view::StringInsertView}, - leveled_term_view::LeveledTermView - } -}; - -//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> -/* -struct ListView { - opening: OuterViewPort>, - closing: OuterViewPort>, - delim: OuterViewPort>, - - data: Option>>>>, - cast: Arc> -} - -impl View for ListView { - type Msg = usize; -} - -impl SequenceView for ListView { - type Item = OuterViewPort>; - - fn get(&self, idx: usize) -> Option { - let len = self.data.len(); - - if idx == 0 { - Some(self.opening.clone()) - } else if idx < len*2 { - if idx % 2 == 1 { - self.data.get(idx / 2) - } else { - Some(self.delim.clone()) - } - } else if idx == len*2 { - Some(self.closing.clone()) - } else { - None - } - } -} - -impl Observer>>> for ListView { - fn reset(&mut self, v: Option>>>>) { - self.data = v; - } - - fn notify(&self, idx: usize) { - - } -} - -impl ListView { - fn new( - data: OuterViewPort>>>, - port: InnerViewPort>>> - ) -> Self { - let - } -} - */ - - -#[async_std::main] -async fn main() { - let term_port = ViewPort::::new(); - - let mut compositor = TerminalCompositor::new(term_port.inner()); - //compositor.push(ViewPort::::with_view(Arc::new(ScrambleBackground)).into_outer()); - - let mut term = Terminal::new(term_port.outer()); - let term_writer = term.get_writer(); - - task::spawn(async move { - /*\ - <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - Setup Views - <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - \*/ - - let window_size_port = ViewPort::new(); - let mut window_size = SingletonBuffer::new(Vector2::new(0, 0), window_size_port.inner()); - - let str_list_port = ViewPort::new(); - let mut str_list = VecBuffer::>>::new(str_list_port.inner()); - - compositor.write().unwrap().push( - str_list_port.outer() - .to_sequence() - .flatten() - .to_index() - .map_key( - |idx| Point2::new(*idx as i16, 0 as i16), - |pt| if pt.y == 0 { Some(pt.x as usize) } else { None } - ) - ); - - //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - // welcome message - task::spawn(async move { - let opening_port = ViewPort::new(); - let mut opening = VecBuffer::new(opening_port.inner()); - - let delim_port = ViewPort::new(); - let mut delim = VecBuffer::new(delim_port.inner()); - - let closing_port = ViewPort::new(); - let mut closing = VecBuffer::new(closing_port.inner()); - - let e1_port = ViewPort::new(); - let mut e1 = VecBuffer::new(e1_port.inner()); - - let e2_port = ViewPort::new(); - let mut e2 = VecBuffer::new(e2_port.inner()); - - opening.push(TerminalAtom::new('[', TerminalStyle::fg_color((180, 120, 80)))); - delim.push(TerminalAtom::new(',', TerminalStyle::fg_color((180, 120, 80)))); - delim.push(TerminalAtom::new(' ', TerminalStyle::fg_color((180, 120, 80)))); - closing.push(TerminalAtom::new(']', TerminalStyle::fg_color((180, 120, 80)))); - - str_list.push(opening_port.outer().to_sequence()); - str_list.push(closing_port.outer().to_sequence()); - - task::sleep(std::time::Duration::from_millis(500)).await; - str_list.insert(1, e1_port.outer().to_sequence()); - - for c in "Welcome!".chars() { - e1.push(TerminalAtom::new(c, TerminalStyle::fg_color((180, 180, 255)))); - task::sleep(std::time::Duration::from_millis(80)).await; - } - - task::sleep(std::time::Duration::from_millis(500)).await; - str_list.insert(2, delim_port.outer().to_sequence()); - str_list.insert(3, e2_port.outer().to_sequence()); - task::sleep(std::time::Duration::from_millis(80)).await; - for c in "This is a flattened SequenceView.".chars() { - e2.push(TerminalAtom::new(c, TerminalStyle::fg_color((180, 180, 255)))); - task::sleep(std::time::Duration::from_millis(80)).await; - } - - task::sleep(std::time::Duration::from_millis(500)).await; - - let l2_port = ViewPort::new(); - let mut l2 = VecBuffer::new(l2_port.inner()); - - *str_list.get_mut(1) = l2_port.outer().to_sequence().flatten(); - - l2.push(opening_port.outer().to_sequence()); - - e1.clear(); - l2.push(e1_port.outer().to_sequence()); - l2.push(closing_port.outer().to_sequence()); - - for c in "they can even be NeStEd!".chars() { - e1.push(TerminalAtom::new(c, TerminalStyle::fg_color((180, 180, 255)))); - task::sleep(std::time::Duration::from_millis(80)).await; - } - - loop { - for i in 0 .. 10 { - task::sleep(std::time::Duration::from_millis(60)).await; - - let col = (100+10*i, 55+20*i, 20+ 20*i); - *opening.get_mut(0) = TerminalAtom::new('{', TerminalStyle::fg_color(col)); - *closing.get_mut(0) = TerminalAtom::new('}', TerminalStyle::fg_color(col)); - } - - for i in 0 .. 10 { - task::sleep(std::time::Duration::from_millis(60)).await; - - let col = (100+10*i, 55+20*i, 20+ 20*i); - *opening.get_mut(0) = TerminalAtom::new('<', TerminalStyle::fg_color(col)); - *closing.get_mut(0) = TerminalAtom::new('>', TerminalStyle::fg_color(col)); - } - } - }); - - //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - // string editor 1 - let mut editor = StringEditor::new(); - let (leveled_edit_view, leveled_edit_view_port) = LeveledTermView::new(editor.insert_view()); - - //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - // string editor 2 - let mut editor2 = StringEditor::new(); - let (leveled_edit2_view, leveled_edit2_view_port) = LeveledTermView::new(editor2.insert_view()); - - compositor.write().unwrap().push( - leveled_edit_view_port - .map_key( - |p| p + Vector2::new(1, 1), - |p| Some(p - Vector2::new(1, 1)) - ) - ); - - compositor.write().unwrap().push( - leveled_edit2_view_port - .map_key( - |p| p + Vector2::new(1, 2), - |p| Some(p - Vector2::new(1, 2)) - ) - ); - - - /*\ - <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - Event Loop - <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - \*/ - - let mut sel = 0 as usize; - - leveled_edit_view.write().unwrap().set_level(if sel == 0 {1} else {0}); - leveled_edit2_view.write().unwrap().set_level(if sel == 1 {1} else {0}); - - loop { - let ed = match sel { - 0 => &mut editor, - 1 => &mut editor2, - _ => &mut editor2 - }; - - match term.next_event().await { - TerminalEvent::Resize(size) => window_size.set(size), - TerminalEvent::Input(Event::Key(Key::Up)) => { - sel = 0; - - leveled_edit_view.write().unwrap().set_level(if sel == 0 {1} else {0}); - leveled_edit2_view.write().unwrap().set_level(if sel == 1 {1} else {0}); - }, - TerminalEvent::Input(Event::Key(Key::Down)) => { - sel = 1; - - leveled_edit_view.write().unwrap().set_level(if sel == 0 {1} else {0}); - leveled_edit2_view.write().unwrap().set_level(if sel == 1 {1} else {0}); - }, - TerminalEvent::Input(Event::Key(Key::Left)) => ed.prev(), - TerminalEvent::Input(Event::Key(Key::Right)) => ed.next(), - TerminalEvent::Input(Event::Key(Key::Home)) => ed.goto(0), - TerminalEvent::Input(Event::Key(Key::End)) => ed.goto_end(), - TerminalEvent::Input(Event::Key(Key::Char('\n'))) => {}, - TerminalEvent::Input(Event::Key(Key::Char(c))) => ed.insert(c), - TerminalEvent::Input(Event::Key(Key::Delete)) => ed.delete(), - TerminalEvent::Input(Event::Key(Key::Backspace)) => ed.delete_prev(), - TerminalEvent::Input(Event::Key(Key::Ctrl('c'))) => break, - _ => {} - } - } - }); - - /*\ - <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - Terminal Rendering - <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - \*/ - - term_writer.show().await.ok(); -} - -//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> -struct Checkerboard; -impl ImplIndexView for Checkerboard { - type Key = Point2; - type Value = TerminalAtom; - - fn get(&self, pos: &Point2) -> Option { - if pos.x == 0 || pos.x == 1 || pos.x > 17 || pos.y == 0 || pos.y > 8 { - // border - Some(TerminalAtom::new_bg((20, 10, 10))) - } else { - // field - if ((pos.x/2) % 2 == 0) ^ ( pos.y % 2 == 0 ) { - Some(TerminalAtom::new_bg((0, 0, 0))) - } else { - Some(TerminalAtom::new_bg((200, 200, 200))) - } - } - } - - fn area(&self) -> Option>> { - Some(GridWindowIterator::from(Point2::new(0,0) .. Point2::new(20,10)).collect()) - } -} - -//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> -struct TermLabel(String); -impl ImplIndexView for TermLabel { - type Key = Point2; - type Value = TerminalAtom; - - fn get(&self, pos: &Point2) -> Option { - if pos.y == 5 { - Some(TerminalAtom::new(self.0.chars().nth(pos.x as usize)?, TerminalStyle::fg_color((255, 255, 255)))) - } 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; - type Value = TerminalAtom; - - fn get(&self, pos: &Point2) -> Option { - if ((pos.x/2) % 2 == 0) ^ (pos.y % 2 == 0) { - Some(TerminalAtom::new(char::from((35+(5*pos.y+pos.x)%40) as u8), TerminalStyle::fg_color((40, 40, 40)))) - } else { - Some(TerminalAtom::new(char::from((35+(pos.y+9*pos.x)%40) as u8), TerminalStyle::fg_color((90, 90, 90)))) - } - } - - fn area(&self) -> Option>> { - None - } -} -