further restructuring

This commit is contained in:
Michael Sippel 2023-11-28 20:52:25 +01:00
parent f151f9c5d2
commit 85b614a9bb
Signed by: senvas
GPG key ID: F96CF119C34B64A6
41 changed files with 95 additions and 125 deletions

View file

@ -6,65 +6,22 @@ extern crate termion;
use { use {
cgmath::Vector2, cgmath::Vector2,
nested::reprTree::Context, nested::repr_tree::Context,
nested_tty::{Terminal, TerminalCompositor, TerminalEvent, TerminalStyle, TerminalView}, nested_tty::{Terminal, TerminalCompositor, TTYApplication, TerminalEvent, TerminalStyle, TerminalView},
r3vi::view::{port::UpdateTask, ViewPort}, r3vi::view::{port::UpdateTask, ViewPort},
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
termion::event::{Event, Key}, termion::event::{Event, Key},
}; };
/* this task handles all terminal events (e.g. key press, resize)
*/
pub async fn event_loop(
mut term: Terminal,
term_port: ViewPort<dyn TerminalView>,
portmutex: Arc<RwLock<()>>,
) {
loop {
let ev = term.next_event().await;
let _l = portmutex.write().unwrap();
if ev == TerminalEvent::Input(Event::Key(Key::Ctrl('d'))) {
break;
}
term_port.update();
}
}
/* this task will continuously pull forward
* all notifications which are influencing
* the view in `term_port`
*/
pub async fn update_loop(term_port: ViewPort<dyn TerminalView>, portmutex: Arc<RwLock<()>>) {
loop {
{
let _l = portmutex.write().unwrap();
term_port.update();
}
async_std::task::sleep(std::time::Duration::from_millis(500)).await;
}
}
#[async_std::main] #[async_std::main]
async fn main() { async fn main() {
/* initialize our terminal /* initialize our terminal
*/ */
let term_port = ViewPort::new(); let tty_app = TTYApplication::new(|event| { /* handle event */ });
let mut term = Terminal::new(term_port.outer());
let term_writer = term.get_writer();
let portmutex = Arc::new(RwLock::new(()));
/* spawn event-handling & updating tasks
*/
async_std::task::spawn(update_loop(term_port.clone(), portmutex.clone()));
async_std::task::spawn(event_loop(term, term_port.clone(), portmutex.clone()));
/* populate the view in `term_port` /* populate the view in `term_port`
*/ */
let compositor = TerminalCompositor::new(term_port.inner()); let compositor = TerminalCompositor::new(tty_app.port.inner());
compositor compositor
.write() .write()
@ -81,5 +38,6 @@ async fn main() {
/* write the changes in the view of `term_port` to the terminal /* write the changes in the view of `term_port` to the terminal
*/ */
term_writer.show().await.expect("output error!"); tty_app.show().await.expect("output error!");
} }

View file

@ -7,8 +7,8 @@ extern crate termion;
use { use {
cgmath::Vector2, cgmath::Vector2,
nested::{ nested::{
editTree::NestedNode, edit_tree::NestedNode,
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
}, },
nested_tty::{ nested_tty::{
terminal::TermOutWriter, DisplaySegment, Terminal, TerminalAtom, TerminalCompositor, terminal::TermOutWriter, DisplaySegment, Terminal, TerminalAtom, TerminalCompositor,
@ -23,18 +23,37 @@ use {
termion::event::{Event, Key}, termion::event::{Event, Key},
}; };
fn node_make_char_view(
node: NestedNode
) -> NestedNode {
let char_view = node.data
.read()
.unwrap()
.get_port::<dyn SingletonView<Item = char>>()
.expect("unable to get Char-view")
.map(move |c| TerminalAtom::from(if c == '\0' { ' ' } else { c }))
.to_grid();
let mut display_rt = ReprTree::new(Context::parse(&node.ctx, "Display"));
display_rt.insert_branch(ReprTree::new_leaf(
Context::parse(&node.ctx, "TerminalView"),
char_view.into(),
));
node.set_view(
Arc::new(RwLock::new(display_rt))
)
}
#[async_std::main] #[async_std::main]
async fn main() { async fn main() {
let app = TTYApplication::new( |ev| { /* event handler */ } ); let app = TTYApplication::new( |ev| { /* event handler */ } );
let compositor = TerminalCompositor::new(app.port.inner());
/* setup context & create Editor-Tree /* setup context & create Editor-Tree
*/ */
let ctx = Arc::new(RwLock::new(Context::default())); let ctx = Arc::new(RwLock::new(Context::default()));
// abstract data
let rt = ReprTree::from_char(&ctx, 'λ');
let mut node = Context::make_node( let mut node = Context::make_node(
&ctx, &ctx,
// node type // node type
@ -44,25 +63,17 @@ async fn main() {
) )
.unwrap(); .unwrap();
/* add a display view to the node // set abstract data
node.data = ReprTree::from_char(&ctx, 'Λ');
// add a display view to the node
node = node_make_char_view( node );
/* setup display view routed to `app.port`
*/ */
let char_view = rt let compositor = TerminalCompositor::new(app.port.inner());
.read()
.unwrap()
.get_port::<dyn SingletonView<Item = char>>()
.expect("unable to get Char-view")
.map(move |c| TerminalAtom::from(if c == '\0' { ' ' } else { c }))
.to_grid();
let mut display_rt = ReprTree::new(Context::parse(&ctx, "Display"));
display_rt.insert_branch(ReprTree::new_leaf(
Context::parse(&ctx, "TerminalView"),
char_view.into(),
));
node = node.set_view(Arc::new(RwLock::new(display_rt)));
// add some views to the display compositor
compositor.write().unwrap().push( compositor.write().unwrap().push(
nested_tty::make_label("Hello World") nested_tty::make_label("Hello World")
.map_item(|p, a| { .map_item(|p, a| {

View file

@ -4,7 +4,7 @@ use {
buffer::{vec::*, index_hashmap::*} buffer::{vec::*, index_hashmap::*}
}, },
crate::{ crate::{
reprTree::ReprTree repr_tree::ReprTree
}, },
std::sync::{Arc, RwLock}, std::sync::{Arc, RwLock},
cgmath::Point2 cgmath::Point2

View file

@ -15,7 +15,7 @@ use {
}, },
crate::{ crate::{
editors::list::ListCursorMode, editors::list::ListCursorMode,
editTree::TreeCursor edit_tree::TreeCursor
}, },
cgmath::Vector2, cgmath::Vector2,
}; };

View file

@ -7,8 +7,8 @@ use {
}, },
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
reprTree::{ReprTree, Context}, repr_tree::{ReprTree, Context},
editTree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp, diagnostics::{Diagnostics, Message}}, edit_tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp, diagnostics::{Diagnostics, Message}},
editors::{list::{ListCursorMode}, ObjCommander} editors::{list::{ListCursorMode}, ObjCommander}
} }
}; };

View file

@ -2,7 +2,7 @@
use { use {
laddertypes::{TypeTerm, TypeID}, laddertypes::{TypeTerm, TypeID},
crate::{ crate::{
editTree::{TreeAddr} edit_tree::{TreeAddr}
} }
}; };

View file

@ -8,8 +8,8 @@ use {
}, },
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
editTree::{NestedNode, TreeNavResult}, edit_tree::{NestedNode, TreeNavResult},
editors::ObjCommander, editors::ObjCommander,
}, },
std::sync::Arc, std::sync::Arc,

View file

@ -5,8 +5,8 @@ use {
}, },
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
reprTree::{Context}, repr_tree::{Context},
reprTree::{MorphismTypePattern}, repr_tree::{MorphismTypePattern},
editors::{ editors::{
list::*, list::*,
integer::* integer::*

View file

@ -13,8 +13,8 @@ use {
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
editors::{list::{ListCmd}, ObjCommander}, editors::{list::{ListCmd}, ObjCommander},
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
editTree::{NestedNode, TreeNav, TreeNavResult, TreeCursor, diagnostics::{Message}}, edit_tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor, diagnostics::{Message}},
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,

View file

@ -4,8 +4,8 @@ use {
}, },
crate::{ crate::{
editors::{list::{ListEditor, ListCursor, ListCursorMode}, ObjCommander}, editors::{list::{ListEditor, ListCursor, ListCursorMode}, ObjCommander},
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
editTree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, edit_tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
}, },
std::sync::{Arc, RwLock} std::sync::{Arc, RwLock}
}; };

View file

@ -2,7 +2,7 @@ use {
r3vi::{view::{OuterViewPort, singleton::*}}, r3vi::{view::{OuterViewPort, singleton::*}},
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
reprTree::{Context}, repr_tree::{Context},
editors::list::{ListEditor}//, PTYListController, PTYListStyle} editors::list::{ListEditor}//, PTYListController, PTYListStyle}
}, },
std::sync::{Arc, RwLock} std::sync::{Arc, RwLock}

View file

@ -5,8 +5,8 @@ use {
}, },
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
editTree::{NestedNode, TreeNav, TreeCursor, diagnostics::Diagnostics}, edit_tree::{NestedNode, TreeNav, TreeCursor, diagnostics::Diagnostics},
editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander}, editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander},
}, },
std::sync::{Arc, RwLock} std::sync::{Arc, RwLock}

View file

@ -11,7 +11,7 @@ use {
ListCursor, ListCursorMode, ListCursor, ListCursorMode,
editor::ListEditor editor::ListEditor
}, },
editTree::{TreeCursor, TreeNav, TreeNavResult, TreeHeightOp} edit_tree::{TreeCursor, TreeNav, TreeNavResult, TreeHeightOp}
}, },
cgmath::Vector2 cgmath::Vector2
}; };

View file

@ -9,7 +9,7 @@ use {
}, },
crate::{ crate::{
editors::list::{ListCursor, ListCursorMode}, editors::list::{ListCursor, ListCursorMode},
editTree::{NestedNode} edit_tree::{NestedNode}
}, },
std::sync::Arc, std::sync::Arc,
std::sync::RwLock, std::sync::RwLock,

View file

@ -16,8 +16,8 @@ pub trait Commander {
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use crate::{ use crate::{
reprTree::ReprTree, repr_tree::ReprTree,
editTree::nav::TreeNavResult edit_tree::nav::TreeNavResult
}; };
pub trait ObjCommander { pub trait ObjCommander {

View file

@ -9,8 +9,8 @@ use {
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
editors::{list::ListCursorMode, ObjCommander}, editors::{list::ListCursorMode, ObjCommander},
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
editTree::{TreeNav, TreeCursor, TreeNavResult, diagnostics::{Diagnostics, Message}, NestedNode}, edit_tree::{TreeNav, TreeCursor, TreeNavResult, diagnostics::{Diagnostics, Message}, NestedNode},
}, },
cgmath::{Vector2}, cgmath::{Vector2},
std::sync::{Arc, RwLock} std::sync::{Arc, RwLock}

View file

@ -3,8 +3,8 @@ use {
view::{singleton::*} view::{singleton::*}
}, },
crate::{ crate::{
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
editTree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, edit_tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
editors::{list::{ListEditor, ListCmd, ListCursorMode}, ObjCommander}, editors::{list::{ListEditor, ListCmd, ListCursorMode}, ObjCommander},
}, },
std::{sync::{Arc, RwLock}}, std::{sync::{Arc, RwLock}},

View file

@ -4,7 +4,7 @@ use {
}, },
laddertypes::{TypeTerm}, laddertypes::{TypeTerm},
crate::{ crate::{
reprTree::{Context, MorphismTypePattern}, repr_tree::{Context, MorphismTypePattern},
editors::{ editors::{
list::{ListEditor, ListSegmentSequence}, list::{ListEditor, ListSegmentSequence},
typeterm::{State, TypeTermEditor} typeterm::{State, TypeTermEditor}

View file

@ -11,8 +11,8 @@ use {
}, },
laddertypes::{TypeID, TypeTerm}, laddertypes::{TypeID, TypeTerm},
crate::{ crate::{
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
editTree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, edit_tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
editors::{list::{ListCursorMode, ListEditor, ListCmd}, ObjCommander}, editors::{list::{ListCursorMode, ListEditor, ListCmd}, ObjCommander},
}, },
std::{sync::{Arc, RwLock}} std::{sync::{Arc, RwLock}}

View file

@ -7,7 +7,7 @@ use {
} }
}, },
crate::{ crate::{
editTree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp}, edit_tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp},
editors::{typeterm::TypeTermEditor, list::ListCursorMode} editors::{typeterm::TypeTermEditor, list::ListCursorMode}
}, },
cgmath::Vector2 cgmath::Vector2

View file

@ -1,5 +1,6 @@
pub mod utils;
pub mod editors; pub mod repr_tree;
pub mod editTree; pub mod edit_tree;
pub mod reprTree; pub mod editors;
pub mod utils;

View file

@ -2,8 +2,8 @@
r3vi::{view::{OuterViewPort, singleton::*}, buffer::{singleton::*}}, r3vi::{view::{OuterViewPort, singleton::*}, buffer::{singleton::*}},
laddertypes::{TypeDict, TypeTerm, TypeID}, laddertypes::{TypeDict, TypeTerm, TypeID},
crate::{ crate::{
reprTree::{ReprTree}, repr_tree::{ReprTree},
editTree::NestedNode edit_tree::NestedNode
}, },
std::{ std::{
collections::HashMap, collections::HashMap,

View file

@ -10,7 +10,8 @@ use {
projection::projection_helper::ProjectionHelper, projection::projection_helper::ProjectionHelper,
}, },
crate::{ crate::{
TerminalAtom, TerminalStyle, TerminalView, atom::{TerminalAtom, TerminalStyle},
TerminalView,
}, },
cgmath::{Point2, Vector2}, cgmath::{Point2, Vector2},
std::io::Read, std::io::Read,

View file

@ -1,7 +1,7 @@
use { pub mod style;
super::TerminalStyle, pub use style::TerminalStyle;
serde::{Deserialize, Serialize},
}; use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Serialize, Deserialize, Debug)] #[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub struct TerminalAtom { pub struct TerminalAtom {

View file

View file

View file

View file

View file

@ -1,10 +1,9 @@
#![feature(trait_alias)] #![feature(trait_alias)]
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> // <<<<>>>><<>><><<>><<< * >>><<>><><<>><<<<>>>> \\
pub mod atom; pub mod atom;
pub mod style;
pub mod compositor; pub mod compositor;
pub mod ansi_parser; pub mod ansi_parser;
@ -12,26 +11,25 @@ pub mod ansi_parser;
pub mod terminal; pub mod terminal;
pub mod tty_application; pub mod tty_application;
//pub mod list_editor; //pub mod edit_tree;
//pub mod widgets; //pub mod widgets;
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> // <<<<>>>><<>><><<>><<< * >>><<>><><<>><<<<>>>> \\
pub use { pub use {
atom::TerminalAtom, atom::{TerminalAtom, TerminalStyle},
compositor::TerminalCompositor,
style::TerminalStyle,
terminal::{Terminal, TerminalEvent}, terminal::{Terminal, TerminalEvent},
tty_application::TTYApplication tty_application::TTYApplication,
compositor::TerminalCompositor,
}; };
use r3vi::view::grid::*; use r3vi::view::grid::*;
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> // <<<<>>>><<>><><<>><<< * >>><<>><><<>><<<<>>>> \\
pub trait TerminalView = GridView<Item = TerminalAtom>; pub trait TerminalView = GridView<Item = TerminalAtom>;
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> // <<<<>>>><<>><><<>><<< * >>><<>><><<>><<<<>>>> \\
use r3vi::view::OuterViewPort; use r3vi::view::OuterViewPort;
@ -40,10 +38,10 @@ pub trait DisplaySegment {
} }
use nested::reprTree::Context; use nested::repr_tree::Context;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
impl DisplaySegment for nested::editTree::NestedNode { impl DisplaySegment for nested::edit_tree::NestedNode {
fn display_view(&self) -> OuterViewPort<dyn TerminalView> { fn display_view(&self) -> OuterViewPort<dyn TerminalView> {
self.view.as_ref().unwrap() self.view.as_ref().unwrap()
.read().unwrap() .read().unwrap()

View file

@ -7,7 +7,8 @@ use {
index::*, index::*,
} }
}, },
super::{TerminalStyle, TerminalView}, crate::atom::{TerminalStyle},
crate::{TerminalView},
async_std::{stream::StreamExt, task}, async_std::{stream::StreamExt, task},
cgmath::{Point2, Vector2}, cgmath::{Point2, Vector2},
signal_hook, signal_hook,

View file

@ -1,8 +1,8 @@
use { use {
cgmath::Vector2, cgmath::Vector2,
nested::{ nested::{
editTree::NestedNode, edit_tree::NestedNode,
reprTree::{Context, ReprTree}, repr_tree::{Context, ReprTree},
}, },
crate::{ crate::{
terminal::TermOutWriter, DisplaySegment, Terminal, TerminalAtom, TerminalCompositor, terminal::TermOutWriter, DisplaySegment, Terminal, TerminalAtom, TerminalCompositor,