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 {
cgmath::Vector2,
nested::reprTree::Context,
nested_tty::{Terminal, TerminalCompositor, TerminalEvent, TerminalStyle, TerminalView},
nested::repr_tree::Context,
nested_tty::{Terminal, TerminalCompositor, TTYApplication, TerminalEvent, TerminalStyle, TerminalView},
r3vi::view::{port::UpdateTask, ViewPort},
std::sync::{Arc, RwLock},
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 fn main() {
/* initialize our terminal
*/
let term_port = ViewPort::new();
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()));
let tty_app = TTYApplication::new(|event| { /* handle event */ });
/* populate the view in `term_port`
*/
let compositor = TerminalCompositor::new(term_port.inner());
let compositor = TerminalCompositor::new(tty_app.port.inner());
compositor
.write()
@ -81,5 +38,6 @@ async fn main() {
/* 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 {
cgmath::Vector2,
nested::{
editTree::NestedNode,
reprTree::{Context, ReprTree},
edit_tree::NestedNode,
repr_tree::{Context, ReprTree},
},
nested_tty::{
terminal::TermOutWriter, DisplaySegment, Terminal, TerminalAtom, TerminalCompositor,
@ -23,18 +23,37 @@ use {
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 fn main() {
let app = TTYApplication::new( |ev| { /* event handler */ } );
let compositor = TerminalCompositor::new(app.port.inner());
/* setup context & create Editor-Tree
*/
let ctx = Arc::new(RwLock::new(Context::default()));
// abstract data
let rt = ReprTree::from_char(&ctx, 'λ');
let mut node = Context::make_node(
&ctx,
// node type
@ -44,25 +63,17 @@ async fn main() {
)
.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
.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)));
let compositor = TerminalCompositor::new(app.port.inner());
// add some views to the display compositor
compositor.write().unwrap().push(
nested_tty::make_label("Hello World")
.map_item(|p, a| {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

View file

View file

View file

View file

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

View file

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

View file

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