wip refactor crates
This commit is contained in:
parent
6b2f8ee66f
commit
4bf03c356d
69 changed files with 238 additions and 1003 deletions
10
Cargo.toml
10
Cargo.toml
|
@ -1,10 +1,6 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"nested",
|
"lib-nested-core",
|
||||||
# "terminal/display_server",
|
"lib-nested-tty"
|
||||||
# "terminal/ansi_parser",
|
|
||||||
# "math/str2int",
|
|
||||||
# "math/int2str",
|
|
||||||
# "math/radix_transform",
|
|
||||||
# "math/fib"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,7 @@ r3vi = { path = "../../lib-r3vi" }
|
||||||
laddertypes = { path = "../../lib-laddertypes" }
|
laddertypes = { path = "../../lib-laddertypes" }
|
||||||
no_deadlocks = "*"
|
no_deadlocks = "*"
|
||||||
cgmath = { version = "0.18.0", features = ["serde"] }
|
cgmath = { version = "0.18.0", features = ["serde"] }
|
||||||
termion = "2.0.1"
|
|
||||||
vte = "0.10.1"
|
|
||||||
ansi_colours = "1.0"
|
|
||||||
signal-hook = "0.3.1"
|
|
||||||
signal-hook-async-std = "0.2.0"
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
serde_json = "*"
|
serde_json = "*"
|
||||||
|
|
||||||
[dependencies.async-std]
|
|
||||||
version = "1.9.0"
|
|
||||||
features = ["unstable", "attributes"]
|
|
|
@ -9,9 +9,8 @@ use {
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
terminal::{TerminalAtom},
|
|
||||||
tree::{NestedNode, TreeNavResult},
|
tree::{NestedNode, TreeNavResult},
|
||||||
commander::{ObjCommander}
|
editors::ObjCommander,
|
||||||
},
|
},
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
std::sync::RwLock
|
std::sync::RwLock
|
||||||
|
@ -49,7 +48,7 @@ impl ObjCommander for CharEditor {
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,20 +82,15 @@ impl CharEditor {
|
||||||
),
|
),
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
|
/* todo: move to lib-nested-term
|
||||||
.set_view(data
|
.set_view(data
|
||||||
.get_port()
|
.get_port()
|
||||||
.map(move |c| TerminalAtom::from(if c == '\0' { ' ' } else { c }))
|
.map(move |c| TerminalAtom::from(if c == '\0' { ' ' } else { c }))
|
||||||
.to_grid()
|
.to_grid()
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
.set_cmd( editor.clone() )
|
.set_cmd( editor.clone() )
|
||||||
.set_editor( editor.clone() )
|
.set_editor( editor.clone() )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
use crate::StringGen;
|
|
||||||
impl StringGen for CharEditor {
|
|
||||||
fn get_string(&self) -> String {
|
|
||||||
String::from(self.get())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -62,6 +62,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
match args[1] {
|
match args[1] {
|
||||||
TypeTerm::Num(_radix) => {
|
TypeTerm::Num(_radix) => {
|
||||||
|
/* FIXME
|
||||||
PTYListController::for_node(
|
PTYListController::for_node(
|
||||||
&mut node,
|
&mut node,
|
||||||
Some(','),
|
Some(','),
|
||||||
|
@ -72,7 +73,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
&mut node,
|
&mut node,
|
||||||
("0d", "", "")
|
("0d", "", "")
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
Some(node)
|
Some(node)
|
||||||
},
|
},
|
||||||
_ => None
|
_ => None
|
|
@ -13,13 +13,8 @@ use {
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
editors::list::{ListCmd, PTYListController, PTYListStyle},
|
editors::{list::{ListCmd}, ObjCommander},
|
||||||
terminal::{
|
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor, diagnostics::{Message}},
|
||||||
TerminalAtom, TerminalStyle, make_label
|
|
||||||
},
|
|
||||||
diagnostics::{Message},
|
|
||||||
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
|
||||||
commander::ObjCommander
|
|
||||||
},
|
},
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
std::sync::RwLock,
|
std::sync::RwLock,
|
||||||
|
@ -56,6 +51,8 @@ impl ObjCommander for DigitEditor {
|
||||||
add a message to the diagnostics view
|
add a message to the diagnostics view
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
let message = IndexBuffer::from_iter(vec![
|
let message = IndexBuffer::from_iter(vec![
|
||||||
(Point2::new(1, 0), make_label("invalid digit '")),
|
(Point2::new(1, 0), make_label("invalid digit '")),
|
||||||
(Point2::new(2, 0), make_label(&format!("{}", c))
|
(Point2::new(2, 0), make_label(&format!("{}", c))
|
||||||
|
@ -64,6 +61,8 @@ impl ObjCommander for DigitEditor {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
self.msg.push(crate::diagnostics::make_error(message.get_port().flatten()));
|
self.msg.push(crate::diagnostics::make_error(message.get_port().flatten()));
|
||||||
|
*/
|
||||||
|
|
||||||
self.data.set(Some(c));
|
self.data.set(Some(c));
|
||||||
} else {
|
} else {
|
||||||
self.data.set(Some(c));
|
self.data.set(Some(c));
|
||||||
|
@ -93,6 +92,7 @@ impl DigitEditor {
|
||||||
|
|
||||||
NestedNode::new(ed.ctx.clone(), data, depth)
|
NestedNode::new(ed.ctx.clone(), data, depth)
|
||||||
.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
|
/*
|
||||||
.set_view(
|
.set_view(
|
||||||
ed.data
|
ed.data
|
||||||
.get_port()
|
.get_port()
|
||||||
|
@ -112,6 +112,7 @@ impl DigitEditor {
|
||||||
.set_diag(
|
.set_diag(
|
||||||
ed.msg.get_port().to_sequence()
|
ed.msg.get_port().to_sequence()
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Option<u32>>> {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SingletonView<Item = Option<u32>>> {
|
||||||
|
@ -159,7 +160,7 @@ impl PosIntEditor {
|
||||||
TypeTerm::TypeID(ctx.read().unwrap().get_typeid("BigEndian").unwrap())
|
TypeTerm::TypeID(ctx.read().unwrap().get_typeid("BigEndian").unwrap())
|
||||||
]
|
]
|
||||||
));
|
));
|
||||||
|
/*
|
||||||
PTYListController::for_node( &mut node, Some(' '), None );
|
PTYListController::for_node( &mut node, Some(' '), None );
|
||||||
PTYListStyle::for_node( &mut node,
|
PTYListStyle::for_node( &mut node,
|
||||||
(
|
(
|
||||||
|
@ -174,7 +175,7 @@ impl PosIntEditor {
|
||||||
"".into()
|
"".into()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
PosIntEditor {
|
PosIntEditor {
|
||||||
radix,
|
radix,
|
||||||
digits: node
|
digits: node
|
|
@ -3,10 +3,9 @@ use {
|
||||||
view::{singleton::*}
|
view::{singleton::*}
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
editors::list::{ListEditor, ListCursor, ListCursorMode},
|
editors::{list::{ListEditor, ListCursor, ListCursorMode}, ObjCommander},
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||||
commander::{ObjCommander}
|
|
||||||
},
|
},
|
||||||
std::sync::{Arc, RwLock}
|
std::sync::{Arc, RwLock}
|
||||||
};
|
};
|
|
@ -3,7 +3,7 @@ use {
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context},
|
type_system::{Context},
|
||||||
editors::list::{ListEditor, PTYListController, PTYListStyle}
|
editors::list::{ListEditor}//, PTYListController, PTYListStyle}
|
||||||
},
|
},
|
||||||
std::sync::{Arc, RwLock}
|
std::sync::{Arc, RwLock}
|
||||||
};
|
};
|
||||||
|
@ -24,8 +24,8 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
|
|
||||||
let mut node = ListEditor::new(ctx.clone(), typ).into_node(depth);
|
let mut node = ListEditor::new(ctx.clone(), typ).into_node(depth);
|
||||||
|
|
||||||
PTYListController::for_node( &mut node, Some(','), Some('}') );
|
// PTYListController::for_node( &mut node, Some(','), Some('}') );
|
||||||
PTYListStyle::for_node( &mut node, ("{",", ","}") );
|
// PTYListStyle::for_node( &mut node, ("{",", ","}") );
|
||||||
|
|
||||||
Some(node)
|
Some(node)
|
||||||
} else {
|
} else {
|
|
@ -1,15 +1,13 @@
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{ViewPort, OuterViewPort, singleton::*, sequence::*},
|
view::{OuterViewPort, singleton::*, sequence::*},
|
||||||
buffer::{singleton::*, vec::*}
|
buffer::{singleton::*, vec::*}
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
editors::list::{ListCursor, ListCursorMode, ListCmd},
|
editors::{list::{ListCursor, ListCursorMode, ListCmd}, ObjCommander},
|
||||||
tree::{NestedNode, TreeNav, TreeCursor},
|
tree::{NestedNode, TreeNav, TreeCursor, diagnostics::Diagnostics},
|
||||||
diagnostics::Diagnostics,
|
|
||||||
commander::ObjCommander
|
|
||||||
},
|
},
|
||||||
std::sync::{Arc, RwLock}
|
std::sync::{Arc, RwLock}
|
||||||
};
|
};
|
|
@ -1,10 +1,8 @@
|
||||||
|
|
||||||
|
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
pub mod editor;
|
pub mod editor;
|
||||||
pub mod nav;
|
pub mod nav;
|
||||||
pub mod segment;
|
pub mod segment;
|
||||||
pub mod pty_editor;
|
|
||||||
pub mod cmd;
|
pub mod cmd;
|
||||||
pub mod ctx;
|
pub mod ctx;
|
||||||
|
|
||||||
|
@ -12,7 +10,6 @@ pub use {
|
||||||
cursor::{ListCursor, ListCursorMode},
|
cursor::{ListCursor, ListCursorMode},
|
||||||
editor::ListEditor,
|
editor::ListEditor,
|
||||||
segment::{ListSegment, ListSegmentSequence},
|
segment::{ListSegment, ListSegmentSequence},
|
||||||
pty_editor::{PTYListStyle, PTYListController},
|
|
||||||
cmd::ListCmd,
|
cmd::ListCmd,
|
||||||
ctx::init_ctx
|
ctx::init_ctx
|
||||||
};
|
};
|
|
@ -9,10 +9,7 @@ use {
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
editors::list::{ListCursor, ListCursorMode},
|
editors::list::{ListCursor, ListCursorMode},
|
||||||
terminal::{TerminalView, TerminalStyle, make_label},
|
tree::{NestedNode}
|
||||||
tree::{NestedNode, TreeNav},
|
|
||||||
utils::color::{bg_style_from_depth, fg_style_from_depth},
|
|
||||||
PtySegment
|
|
||||||
},
|
},
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
std::sync::RwLock,
|
std::sync::RwLock,
|
||||||
|
@ -26,39 +23,6 @@ pub enum ListSegment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PtySegment for ListSegment {
|
|
||||||
fn pty_view(&self) -> OuterViewPort<dyn TerminalView> {
|
|
||||||
match self {
|
|
||||||
ListSegment::InsertCursor => {
|
|
||||||
make_label("|")
|
|
||||||
.map_item(move |_pt, atom| {
|
|
||||||
atom.add_style_front(TerminalStyle::fg_color((150,80,230)))
|
|
||||||
.add_style_front(TerminalStyle::bold(true))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
ListSegment::Item{ editor, cur_dist } => {
|
|
||||||
let e = editor.clone();
|
|
||||||
let cur_dist = *cur_dist;
|
|
||||||
editor.get_view().map_item(move |_pt, atom| {
|
|
||||||
let c = e.get_cursor();
|
|
||||||
let cur_depth = c.tree_addr.len();
|
|
||||||
let select =
|
|
||||||
if cur_dist == 0 {
|
|
||||||
cur_depth
|
|
||||||
} else {
|
|
||||||
usize::MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
atom
|
|
||||||
.add_style_back(bg_style_from_depth(select))
|
|
||||||
.add_style_back(TerminalStyle::bold(select==1))
|
|
||||||
.add_style_back(fg_style_from_depth(e.depth.get_view().get()))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ListSegmentSequence {
|
pub struct ListSegmentSequence {
|
||||||
data: Arc<dyn SequenceView<Item = NestedNode>>,
|
data: Arc<dyn SequenceView<Item = NestedNode>>,
|
||||||
cursor: Arc<dyn SingletonView<Item = ListCursor>>,
|
cursor: Arc<dyn SingletonView<Item = ListCursor>>,
|
|
@ -1,4 +1,13 @@
|
||||||
|
|
||||||
|
pub mod list;
|
||||||
|
//pub mod product;
|
||||||
|
pub mod sum;
|
||||||
|
|
||||||
|
pub mod char;
|
||||||
|
pub mod integer;
|
||||||
|
pub mod typeterm;
|
||||||
|
|
||||||
|
|
||||||
pub trait Commander {
|
pub trait Commander {
|
||||||
type Cmd;
|
type Cmd;
|
||||||
|
|
|
@ -12,10 +12,6 @@ use {
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context},
|
type_system::{Context},
|
||||||
terminal::{
|
|
||||||
TerminalEditor, TerminalEditorResult,
|
|
||||||
TerminalEvent, TerminalView
|
|
||||||
},
|
|
||||||
editors::{
|
editors::{
|
||||||
list::ListCursorMode,
|
list::ListCursorMode,
|
||||||
product::{
|
product::{
|
|
@ -8,14 +8,9 @@ use {
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
terminal::TerminalView,
|
editors::{list::ListCursorMode, ObjCommander},
|
||||||
editors::list::ListCursorMode,
|
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
tree::{TreeNav, TreeCursor, TreeNavResult},
|
tree::{TreeNav, TreeCursor, TreeNavResult, diagnostics::{Diagnostics, Message}, NestedNode},
|
||||||
diagnostics::{Diagnostics, Message},
|
|
||||||
tree::NestedNode,
|
|
||||||
commander::{ObjCommander},
|
|
||||||
PtySegment
|
|
||||||
},
|
},
|
||||||
cgmath::{Vector2},
|
cgmath::{Vector2},
|
||||||
std::sync::{Arc, RwLock}
|
std::sync::{Arc, RwLock}
|
||||||
|
@ -28,7 +23,7 @@ pub struct SumEditor {
|
||||||
addr_port: ViewPort< dyn SequenceView<Item = isize> >,
|
addr_port: ViewPort< dyn SequenceView<Item = isize> >,
|
||||||
mode_port: ViewPort< dyn SingletonView<Item = ListCursorMode> >,
|
mode_port: ViewPort< dyn SingletonView<Item = ListCursorMode> >,
|
||||||
|
|
||||||
port: ViewPort< dyn TerminalView >,
|
// port: ViewPort< dyn TerminalView >,
|
||||||
diag_port: ViewPort< dyn SequenceView<Item = Message> >
|
diag_port: ViewPort< dyn SequenceView<Item = Message> >
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,12 +31,12 @@ impl SumEditor {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
editors: Vec< NestedNode >
|
editors: Vec< NestedNode >
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let port = ViewPort::new();
|
// let port = ViewPort::new();
|
||||||
|
|
||||||
SumEditor {
|
SumEditor {
|
||||||
cur: 0,
|
cur: 0,
|
||||||
editors,
|
editors,
|
||||||
port,
|
// port,
|
||||||
diag_port: ViewPort::new(),
|
diag_port: ViewPort::new(),
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +50,7 @@ impl SumEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_node(self, ctx: Arc<RwLock<Context>>) -> NestedNode {
|
pub fn into_node(self, ctx: Arc<RwLock<Context>>) -> NestedNode {
|
||||||
let view = self.pty_view();
|
// let view = self.pty_view();
|
||||||
let editor = Arc::new(RwLock::new(self));
|
let editor = Arc::new(RwLock::new(self));
|
||||||
|
|
||||||
NestedNode::new(
|
NestedNode::new(
|
||||||
|
@ -63,7 +58,7 @@ impl SumEditor {
|
||||||
ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())),
|
ReprTree::new_arc(TypeTerm::TypeID(ctx.read().unwrap().get_typeid("Sum").unwrap())),
|
||||||
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()
|
r3vi::buffer::singleton::SingletonBuffer::new(0).get_port()
|
||||||
)
|
)
|
||||||
.set_view(view)
|
// .set_view(view)
|
||||||
.set_editor(editor.clone())
|
.set_editor(editor.clone())
|
||||||
.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
.set_nav(editor.clone())
|
.set_nav(editor.clone())
|
||||||
|
@ -76,6 +71,7 @@ impl SumEditor {
|
||||||
|
|
||||||
pub fn select(&mut self, idx: usize) {
|
pub fn select(&mut self, idx: usize) {
|
||||||
self.cur = idx;
|
self.cur = idx;
|
||||||
|
/* FIXME
|
||||||
|
|
||||||
let tv = self.editors[ self.cur ].get_view();
|
let tv = self.editors[ self.cur ].get_view();
|
||||||
tv.add_observer( self.port.get_cast() );
|
tv.add_observer( self.port.get_cast() );
|
||||||
|
@ -100,6 +96,7 @@ impl SumEditor {
|
||||||
self.mode_port.update_hooks.write().unwrap().clear();
|
self.mode_port.update_hooks.write().unwrap().clear();
|
||||||
self.mode_port.add_update_hook( Arc::new(dv.0.clone()) );
|
self.mode_port.add_update_hook( Arc::new(dv.0.clone()) );
|
||||||
self.mode_port.set_view( Some(dv.get_view_arc()) );
|
self.mode_port.set_view( Some(dv.get_view_arc()) );
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +126,6 @@ impl TreeNav for SumEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PtySegment for SumEditor {
|
|
||||||
fn pty_view(&self) -> OuterViewPort<dyn TerminalView> {
|
|
||||||
self.port.outer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjCommander for SumEditor {
|
impl ObjCommander for SumEditor {
|
||||||
fn send_cmd_obj(&mut self, obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
fn send_cmd_obj(&mut self, obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
self.editors[ self.cur ].send_cmd_obj( obj )
|
self.editors[ self.cur ].send_cmd_obj( obj )
|
|
@ -4,9 +4,8 @@ use {
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
editors::{list::{ListEditor, ListCmd, ListCursorMode}},
|
editors::{list::{ListEditor, ListCmd, ListCursorMode}, ObjCommander},
|
||||||
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||||
commander::ObjCommander
|
|
||||||
},
|
},
|
||||||
std::{sync::{Arc, RwLock}},
|
std::{sync::{Arc, RwLock}},
|
||||||
|
|
|
@ -5,12 +5,10 @@ use {
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, MorphismTypePattern},
|
type_system::{Context, MorphismTypePattern},
|
||||||
terminal::{TerminalStyle, TerminalProjections},
|
|
||||||
editors::{
|
editors::{
|
||||||
list::{PTYListStyle, PTYListController, ListEditor, ListSegmentSequence},
|
list::{ListEditor, ListSegmentSequence},
|
||||||
typeterm::{State, TypeTermEditor}
|
typeterm::{State, TypeTermEditor}
|
||||||
},
|
}
|
||||||
PtySegment
|
|
||||||
},
|
},
|
||||||
std::{sync::{Arc, RwLock}},
|
std::{sync::{Arc, RwLock}},
|
||||||
cgmath::{Point2}
|
cgmath::{Point2}
|
||||||
|
@ -36,7 +34,7 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
let new_node = TypeTermEditor::with_node( ctx, node.clone(), State::Any );
|
let new_node = TypeTermEditor::with_node( ctx, node.clone(), State::Any );
|
||||||
Some(new_node)
|
Some(new_node)
|
||||||
}));
|
}));
|
||||||
|
/*
|
||||||
ctx.add_morphism(
|
ctx.add_morphism(
|
||||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Ladder").unwrap() },
|
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type::Ladder").unwrap() },
|
||||||
Arc::new(|mut node, _dst_type: _| {
|
Arc::new(|mut node, _dst_type: _| {
|
||||||
|
@ -140,5 +138,6 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: OuterViewPort<dyn SingletonView<Item = usize>>| {
|
||||||
Some(TypeTermEditor::new_node(ctx, depth))
|
Some(TypeTermEditor::new_node(ctx, depth))
|
||||||
}));
|
}));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,8 @@ use {
|
||||||
laddertypes::{TypeID, TypeTerm},
|
laddertypes::{TypeID, TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
editors::{list::{ListCursorMode, ListEditor, ListCmd}},
|
editors::{list::{ListCursorMode, ListEditor, ListCmd}, ObjCommander},
|
||||||
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||||
commander::ObjCommander
|
|
||||||
},
|
},
|
||||||
std::{sync::{Arc, RwLock}}
|
std::{sync::{Arc, RwLock}}
|
||||||
};
|
};
|
||||||
|
@ -207,7 +206,7 @@ impl TypeTermEditor {
|
||||||
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
spillbuf: Arc::new(RwLock::new(Vec::new())),
|
||||||
depth: cur_node.depth.clone()
|
depth: cur_node.depth.clone()
|
||||||
};
|
};
|
||||||
|
/* FIXME
|
||||||
let view = editor.cur_node
|
let view = editor.cur_node
|
||||||
.get_port()
|
.get_port()
|
||||||
.map(|node| {
|
.map(|node| {
|
||||||
|
@ -215,11 +214,12 @@ impl TypeTermEditor {
|
||||||
})
|
})
|
||||||
.to_grid()
|
.to_grid()
|
||||||
.flatten();
|
.flatten();
|
||||||
|
*/
|
||||||
let _cc = editor.cur_node.get().close_char;
|
let _cc = editor.cur_node.get().close_char;
|
||||||
let editor = Arc::new(RwLock::new(editor));
|
let editor = Arc::new(RwLock::new(editor));
|
||||||
|
|
||||||
let mut super_node = NestedNode::new(ctx, data, cur_node.depth)
|
let mut super_node = NestedNode::new(ctx, data, cur_node.depth)
|
||||||
.set_view(view)
|
// .set_view(view)
|
||||||
.set_nav(editor.clone())
|
.set_nav(editor.clone())
|
||||||
.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
.set_editor(editor.clone());
|
.set_editor(editor.clone());
|
8
lib-nested-core/src/lib.rs
Normal file
8
lib-nested-core/src/lib.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
pub mod utils;
|
||||||
|
pub mod editors;
|
||||||
|
pub mod tree;
|
||||||
|
pub mod type_system;
|
||||||
|
|
||||||
|
pub fn magic_header() {
|
||||||
|
eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>");
|
||||||
|
}
|
24
lib-nested-core/src/tree/diagnostics.rs
Normal file
24
lib-nested-core/src/tree/diagnostics.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
use {
|
||||||
|
r3vi::{
|
||||||
|
view::{OuterViewPort, sequence::*},
|
||||||
|
buffer::{vec::*, index_hashmap::*}
|
||||||
|
},
|
||||||
|
crate::{
|
||||||
|
type_system::ReprTree
|
||||||
|
},
|
||||||
|
std::sync::{Arc, RwLock},
|
||||||
|
cgmath::Point2
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Message {
|
||||||
|
pub addr: Vec<usize>,
|
||||||
|
pub disp: Arc<RwLock<ReprTree>>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Diagnostics {
|
||||||
|
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = Message>> {
|
||||||
|
VecBuffer::new().get_port().to_sequence()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ pub mod cursor;
|
||||||
pub mod nav;
|
pub mod nav;
|
||||||
pub mod node;
|
pub mod node;
|
||||||
pub mod treetype;
|
pub mod treetype;
|
||||||
|
pub mod diagnostics;
|
||||||
|
|
||||||
pub use {
|
pub use {
|
||||||
addr::TreeAddr,
|
addr::TreeAddr,
|
|
@ -15,8 +15,7 @@ use {
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
editors::list::ListCursorMode,
|
editors::list::ListCursorMode,
|
||||||
tree::TreeCursor,
|
tree::TreeCursor
|
||||||
terminal::{TerminalView, TerminalProjections, make_label}
|
|
||||||
},
|
},
|
||||||
cgmath::Vector2,
|
cgmath::Vector2,
|
||||||
};
|
};
|
||||||
|
@ -150,35 +149,6 @@ pub trait TreeNav {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cursor_widget(&self) -> OuterViewPort<dyn TerminalView> {
|
|
||||||
VecBuffer::with_data(
|
|
||||||
vec![
|
|
||||||
make_label("@").with_fg_color((150, 80,230)),
|
|
||||||
self.get_addr_view()
|
|
||||||
.map(|i|
|
|
||||||
make_label(&format!("{}", i)).with_fg_color((0, 100, 20)))
|
|
||||||
.separate(make_label(".").with_fg_color((150, 80,230)))
|
|
||||||
.to_grid_horizontal()
|
|
||||||
.flatten(),
|
|
||||||
make_label(":").with_fg_color((150, 80,230)),
|
|
||||||
self.get_mode_view()
|
|
||||||
.map(|mode| {
|
|
||||||
make_label(
|
|
||||||
match mode {
|
|
||||||
ListCursorMode::Insert => "INSERT",
|
|
||||||
ListCursorMode::Select => "SELECT"
|
|
||||||
})
|
|
||||||
.with_fg_color((200, 200, 20))
|
|
||||||
})
|
|
||||||
.to_grid()
|
|
||||||
.flatten(),
|
|
||||||
make_label(":").with_fg_color((150, 80,230))
|
|
||||||
]
|
|
||||||
).get_port()
|
|
||||||
.to_sequence()
|
|
||||||
.to_grid_horizontal()
|
|
||||||
.flatten()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,30 +3,28 @@ use {
|
||||||
cgmath::{Vector2, Point2},
|
cgmath::{Vector2, Point2},
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{View, ViewPort, OuterViewPort, AnyOuterViewPort, singleton::*, sequence::*},
|
view::{View, ViewPort, OuterViewPort, AnyOuterViewPort, singleton::*, sequence::*},
|
||||||
buffer::{singleton::*}
|
buffer::{singleton::*, vec::*}
|
||||||
},
|
},
|
||||||
laddertypes::{TypeTerm},
|
laddertypes::{TypeTerm},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{ReprTree, Context},
|
type_system::{ReprTree, Context},
|
||||||
terminal::{TerminalView, TerminalEvent, TerminalEditor, TerminalEditorResult, TerminalAtom},
|
tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp, diagnostics::{Diagnostics, Message}},
|
||||||
diagnostics::{Diagnostics, Message},
|
editors::{list::{ListCursorMode}, ObjCommander}
|
||||||
tree::{TreeNav, TreeCursor, TreeNavResult, TreeHeightOp},
|
|
||||||
editors::list::{ListCursorMode},
|
|
||||||
commander::ObjCommander,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO: refactoring proposal
|
//* TODO: refactoring proposal
|
||||||
|
/*
|
||||||
|
|
||||||
struct NestedNodeDisplay {
|
struct NestedNodeDisplay {
|
||||||
/// display view
|
/// display view
|
||||||
pub view: Option< OuterViewPort<dyn TerminalView> >,
|
pub view: Option< Arc<RwLock<ReprTree>> >,
|
||||||
|
|
||||||
/// diagnostics
|
/// diagnostics
|
||||||
pub diag: Option< OuterViewPort<dyn SequenceView<Item = Message>> >,
|
pub diag: Option< OuterViewPort<dyn SequenceView<Item = diagnostics::Message>> >,
|
||||||
|
|
||||||
/// depth
|
/// depth
|
||||||
pub depth: SingletonBuffer< usize >,
|
pub depth: SingletonBuffer< usize >,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NestedNodeEdit {
|
struct NestedNodeEdit {
|
||||||
|
@ -40,7 +38,9 @@ struct NestedNodeEdit {
|
||||||
/// commander & navigation
|
/// commander & navigation
|
||||||
pub cmd: SingletonBuffer<
|
pub cmd: SingletonBuffer<
|
||||||
Option< Arc<RwLock<dyn ObjCommander + Send + Sync>> >
|
Option< Arc<RwLock<dyn ObjCommander + Send + Sync>> >
|
||||||
>,
|
>, /// abstract data view
|
||||||
|
pub data: Arc<RwLock<ReprTree>>,
|
||||||
|
|
||||||
pub close_char: SingletonBuffer< Option< char > >,
|
pub close_char: SingletonBuffer< Option< char > >,
|
||||||
|
|
||||||
// could be replaced by cmd when TreeNav -CmdObjects are used
|
// could be replaced by cmd when TreeNav -CmdObjects are used
|
||||||
|
@ -62,7 +62,6 @@ pub struct NewNestedNode {
|
||||||
/// editor & commander objects
|
/// editor & commander objects
|
||||||
pub edit: NestedNodeEdit
|
pub edit: NestedNodeEdit
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -74,7 +73,7 @@ pub struct NestedNode {
|
||||||
pub data: Arc<RwLock<ReprTree>>,
|
pub data: Arc<RwLock<ReprTree>>,
|
||||||
|
|
||||||
/// display view
|
/// display view
|
||||||
pub view: Option< OuterViewPort<dyn TerminalView> >,
|
pub view: Option< Arc<RwLock<ReprTree>> >,
|
||||||
|
|
||||||
/// diagnostics
|
/// diagnostics
|
||||||
pub diag: Option< OuterViewPort<dyn SequenceView<Item = Message>> >,
|
pub diag: Option< OuterViewPort<dyn SequenceView<Item = Message>> >,
|
||||||
|
@ -129,7 +128,8 @@ impl NestedNode {
|
||||||
buf.get_port().into()
|
buf.get_port().into()
|
||||||
),
|
),
|
||||||
SingletonBuffer::new(0).get_port()
|
SingletonBuffer::new(0).get_port()
|
||||||
)
|
)
|
||||||
|
/*
|
||||||
.set_view(buf.get_port()
|
.set_view(buf.get_port()
|
||||||
.map(|c| TerminalAtom::from(c))
|
.map(|c| TerminalAtom::from(c))
|
||||||
.to_index()
|
.to_index()
|
||||||
|
@ -141,6 +141,7 @@ impl NestedNode {
|
||||||
if *p == Point2::new(0,0) { Some(()) } else { None }
|
if *p == Point2::new(0,0) { Some(()) } else { None }
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
.set_editor(Arc::new(RwLock::new(buf)))
|
.set_editor(Arc::new(RwLock::new(buf)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +163,7 @@ impl NestedNode {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_view(mut self, view: OuterViewPort<dyn TerminalView>) -> Self {
|
pub fn set_view(mut self, view: Arc<RwLock<ReprTree>>) -> Self {
|
||||||
self.view = Some(view);
|
self.view = Some(view);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -188,8 +189,8 @@ impl NestedNode {
|
||||||
self.diag.clone().unwrap_or(ViewPort::new().into_outer())
|
self.diag.clone().unwrap_or(ViewPort::new().into_outer())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_view(&self) -> OuterViewPort<dyn TerminalView> {
|
pub fn get_view(&self) -> Option< Arc<RwLock<ReprTree>> > {
|
||||||
self.view.clone().unwrap_or(ViewPort::new().into_outer())
|
self.view.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_port<'a, V: View + ?Sized + 'static>(&'a self, type_str: impl Iterator<Item = &'a str>) -> Option<OuterViewPort<V>>
|
pub fn get_data_port<'a, V: View + ?Sized + 'static>(&'a self, type_str: impl Iterator<Item = &'a str>) -> Option<OuterViewPort<V>>
|
||||||
|
@ -246,6 +247,7 @@ impl TreeType for NestedNode {
|
||||||
|
|
||||||
/* TODO: remove that at some point
|
/* TODO: remove that at some point
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
impl TerminalEditor for NestedNode {
|
impl TerminalEditor for NestedNode {
|
||||||
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
|
fn get_term_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
self.get_view()
|
self.get_view()
|
||||||
|
@ -265,7 +267,7 @@ impl TerminalEditor for NestedNode {
|
||||||
TerminalEditorResult::Continue
|
TerminalEditorResult::Continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
impl TreeNav for NestedNode {
|
impl TreeNav for NestedNode {
|
||||||
fn get_cursor(&self) -> TreeCursor {
|
fn get_cursor(&self) -> TreeCursor {
|
||||||
if let Some(tn) = self.tree_nav.get() {
|
if let Some(tn) = self.tree_nav.get() {
|
|
@ -56,6 +56,14 @@ impl ReprTree {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_u64(ctx: &Arc<RwLock<Context>>, v: u64) -> Arc<RwLock<Self>> {
|
||||||
|
let buf = r3vi::buffer::singleton::SingletonBuffer::<u64>::new(v);
|
||||||
|
ReprTree::new_leaf(
|
||||||
|
Context::parse(ctx, "<MachineInt 64>"),
|
||||||
|
buf.get_port().into()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_leaf(type_tag: impl Into<TypeTerm>, port: AnyOuterViewPort) -> Arc<RwLock<Self>> {
|
pub fn new_leaf(type_tag: impl Into<TypeTerm>, port: AnyOuterViewPort) -> Arc<RwLock<Self>> {
|
||||||
let mut tree = ReprTree::new(type_tag.into());
|
let mut tree = ReprTree::new(type_tag.into());
|
||||||
tree.insert_leaf(vec![].into_iter(), port);
|
tree.insert_leaf(vec![].into_iter(), port);
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod bimap;
|
pub mod bimap;
|
||||||
pub mod modulo;
|
pub mod modulo;
|
||||||
pub mod color;
|
|
||||||
|
|
||||||
pub use modulo::modulo;
|
pub use modulo::modulo;
|
||||||
pub use bimap::Bimap;
|
pub use bimap::Bimap;
|
|
@ -1,13 +1,22 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["Michael Sippel <micha@fragmental.art>"]
|
authors = ["Michael Sippel <micha@fragmental.art>"]
|
||||||
name = "ansi_parser"
|
name = "nested-tty"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
nested = { path = "../../nested" }
|
r3vi = { path = "../../lib-r3vi" }
|
||||||
|
nested = { path = "../lib-nested-core" }
|
||||||
cgmath = { version = "0.18.0", features = ["serde"] }
|
cgmath = { version = "0.18.0", features = ["serde"] }
|
||||||
serde = { version = "1.0", features = ["serde_derive"] }
|
serde = { version = "1.0", features = ["serde_derive"] }
|
||||||
bincode = "1.3.3"
|
termion = "2.0.3"
|
||||||
vte = "0.10.1"
|
vte = "0.10.1"
|
||||||
ansi_colours = "1.0"
|
ansi_colours = "1.0"
|
||||||
|
signal-hook = "*"
|
||||||
|
signal-hook-async-std = "*"
|
||||||
|
|
||||||
|
[dependencies.async-std]
|
||||||
|
version = "1.9.0"
|
||||||
|
features = ["unstable", "attributes"]
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use {
|
||||||
projection::projection_helper::ProjectionHelper,
|
projection::projection_helper::ProjectionHelper,
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
terminal::{TerminalAtom, TerminalStyle, TerminalView},
|
TerminalAtom, TerminalStyle, TerminalView,
|
||||||
},
|
},
|
||||||
cgmath::{Point2, Vector2},
|
cgmath::{Point2, Vector2},
|
||||||
std::io::Read,
|
std::io::Read,
|
|
@ -6,7 +6,7 @@ use {
|
||||||
},
|
},
|
||||||
projection::projection_helper::*,
|
projection::projection_helper::*,
|
||||||
},
|
},
|
||||||
crate::{terminal::{TerminalAtom, TerminalView}},
|
crate::{TerminalAtom, TerminalView},
|
||||||
cgmath::Point2,
|
cgmath::Point2,
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
std::sync::RwLock,
|
std::sync::RwLock,
|
33
lib-nested-tty/src/cursor_widget.rs
Normal file
33
lib-nested-tty/src/cursor_widget.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
impl TreeNav {
|
||||||
|
fn get_cursor_widget(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
|
VecBuffer::with_data(
|
||||||
|
vec![
|
||||||
|
make_label("@").with_fg_color((150, 80,230)),
|
||||||
|
self.get_addr_view()
|
||||||
|
.map(|i|
|
||||||
|
make_label(&format!("{}", i)).with_fg_color((0, 100, 20)))
|
||||||
|
.separate(make_label(".").with_fg_color((150, 80,230)))
|
||||||
|
.to_grid_horizontal()
|
||||||
|
.flatten(),
|
||||||
|
make_label(":").with_fg_color((150, 80,230)),
|
||||||
|
self.get_mode_view()
|
||||||
|
.map(|mode| {
|
||||||
|
make_label(
|
||||||
|
match mode {
|
||||||
|
ListCursorMode::Insert => "INSERT",
|
||||||
|
ListCursorMode::Select => "SELECT"
|
||||||
|
})
|
||||||
|
.with_fg_color((200, 200, 20))
|
||||||
|
})
|
||||||
|
.to_grid()
|
||||||
|
.flatten(),
|
||||||
|
make_label(":").with_fg_color((150, 80,230))
|
||||||
|
]
|
||||||
|
).get_port()
|
||||||
|
.to_sequence()
|
||||||
|
.to_grid_horizontal()
|
||||||
|
.flatten()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
use {
|
|
||||||
r3vi::{
|
|
||||||
view::{OuterViewPort, sequence::*},
|
|
||||||
buffer::{vec::*, index_hashmap::*}
|
|
||||||
},
|
|
||||||
crate::{
|
|
||||||
terminal::{
|
|
||||||
TerminalView, TerminalStyle, make_label
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cgmath::Point2
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Message {
|
|
||||||
pub addr: Vec<usize>,
|
|
||||||
pub port: OuterViewPort<dyn TerminalView>
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Diagnostics {
|
|
||||||
fn get_msg_port(&self) -> OuterViewPort<dyn SequenceView<Item = Message>> {
|
|
||||||
VecBuffer::new().get_port().to_sequence()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn make_error(msg: OuterViewPort<dyn TerminalView>) -> Message {
|
pub fn make_error(msg: OuterViewPort<dyn TerminalView>) -> Message {
|
||||||
let mut mb = IndexBuffer::new();
|
let mut mb = IndexBuffer::new();
|
|
@ -1,9 +1,20 @@
|
||||||
pub mod ansi_parser;
|
|
||||||
|
#![feature(trait_alias)]
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
pub mod atom;
|
pub mod atom;
|
||||||
pub mod compositor;
|
|
||||||
pub mod style;
|
pub mod style;
|
||||||
|
|
||||||
|
pub mod compositor;
|
||||||
|
pub mod ansi_parser;
|
||||||
|
|
||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
pub mod widgets;
|
|
||||||
|
//pub mod list_editor;
|
||||||
|
//pub mod widgets;
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
pub use {
|
pub use {
|
||||||
atom::TerminalAtom,
|
atom::TerminalAtom,
|
||||||
|
@ -32,10 +43,17 @@ pub trait TerminalEditor {
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
|
use r3vi::view::OuterViewPort;
|
||||||
|
|
||||||
|
pub trait DisplaySegment {
|
||||||
|
fn display_view(&self) -> OuterViewPort<dyn TerminalView>;
|
||||||
|
}
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
use {
|
use {
|
||||||
r3vi::{
|
r3vi::{
|
||||||
view::{OuterViewPort},
|
buffer::vec::*,
|
||||||
buffer::vec::*,
|
|
||||||
},
|
},
|
||||||
cgmath::Point2,
|
cgmath::Point2,
|
||||||
};
|
};
|
||||||
|
@ -55,6 +73,8 @@ pub fn make_label(s: &str) -> OuterViewPort<dyn TerminalView> {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
pub trait TerminalProjections {
|
pub trait TerminalProjections {
|
||||||
fn with_style(&self, style: TerminalStyle) -> OuterViewPort<dyn TerminalView>;
|
fn with_style(&self, style: TerminalStyle) -> OuterViewPort<dyn TerminalView>;
|
||||||
fn with_fg_color(&self, col: (u8, u8, u8)) -> OuterViewPort<dyn TerminalView>;
|
fn with_fg_color(&self, col: (u8, u8, u8)) -> OuterViewPort<dyn TerminalView>;
|
||||||
|
@ -78,3 +98,4 @@ impl TerminalProjections for OuterViewPort<dyn TerminalView> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,57 @@ use {
|
||||||
view::{ViewPort, OuterViewPort, sequence::*},
|
view::{ViewPort, OuterViewPort, sequence::*},
|
||||||
projection::decorate_sequence::*,
|
projection::decorate_sequence::*,
|
||||||
},
|
},
|
||||||
crate::{
|
nested::{
|
||||||
type_system::{Context, ReprTree},
|
type_system::{Context, ReprTree},
|
||||||
editors::list::*,
|
editors::list::*,
|
||||||
terminal::{TerminalEvent, TerminalView, make_label},
|
|
||||||
tree::{TreeCursor, TreeNav, TreeNavResult},
|
tree::{TreeCursor, TreeNav, TreeNavResult},
|
||||||
tree::NestedNode,
|
tree::NestedNode,
|
||||||
PtySegment
|
PtySegment
|
||||||
},
|
},
|
||||||
|
crate::{
|
||||||
|
TerminalEvent, TerminalView, make_label
|
||||||
|
}
|
||||||
std::sync::{Arc, RwLock},
|
std::sync::{Arc, RwLock},
|
||||||
termion::event::{Event, Key}
|
termion::event::{Event, Key}
|
||||||
};
|
};
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
|
impl PtySegment for ListSegment {
|
||||||
|
fn pty_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
|
match self {
|
||||||
|
ListSegment::InsertCursor => {
|
||||||
|
make_label("|")
|
||||||
|
.map_item(move |_pt, atom| {
|
||||||
|
atom.add_style_front(TerminalStyle::fg_color((150,80,230)))
|
||||||
|
.add_style_front(TerminalStyle::bold(true))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
ListSegment::Item{ editor, cur_dist } => {
|
||||||
|
let e = editor.clone();
|
||||||
|
let cur_dist = *cur_dist;
|
||||||
|
editor.get_view().map_item(move |_pt, atom| {
|
||||||
|
let c = e.get_cursor();
|
||||||
|
let cur_depth = c.tree_addr.len();
|
||||||
|
let select =
|
||||||
|
if cur_dist == 0 {
|
||||||
|
cur_depth
|
||||||
|
} else {
|
||||||
|
usize::MAX
|
||||||
|
};
|
||||||
|
|
||||||
|
atom
|
||||||
|
.add_style_back(bg_style_from_depth(select))
|
||||||
|
.add_style_back(TerminalStyle::bold(select==1))
|
||||||
|
.add_style_back(fg_style_from_depth(e.depth.get_view().get()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
pub struct PTYListStyle {
|
pub struct PTYListStyle {
|
||||||
style: (String, String, String)
|
style: (String, String, String)
|
||||||
}
|
}
|
8
lib-nested-tty/src/sum_editor.rs
Normal file
8
lib-nested-tty/src/sum_editor.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
|
||||||
|
impl PtySegment for SumEditor {
|
||||||
|
fn pty_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
|
self.port.outer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "fib"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
nested = { path = "../../nested" }
|
|
|
@ -1,62 +0,0 @@
|
||||||
use std::{
|
|
||||||
fs::File,
|
|
||||||
io::{Read, Write},
|
|
||||||
os::unix::io::FromRawFd,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn fib(n: u64) -> u64 {
|
|
||||||
let mut y = 0;
|
|
||||||
let mut y1 = 1;
|
|
||||||
let mut y2 = 0;
|
|
||||||
|
|
||||||
for _ in 0..n {
|
|
||||||
y = y1 + y2;
|
|
||||||
y2 = y1;
|
|
||||||
y1 = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
y
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
eprintln!(" Fibonacci Sequence");
|
|
||||||
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
interface (Sequence ℕ) 0 1"
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut f0 = unsafe { File::from_raw_fd(0) };
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
>0: n
|
|
||||||
( ℕ )
|
|
||||||
( MachineInt )
|
|
||||||
( MachineWord )
|
|
||||||
( Stream MachineSyllab )
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut f1 = unsafe { File::from_raw_fd(1) };
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
<1: n'th fibonacci number
|
|
||||||
( ℕ )
|
|
||||||
( MachineInt )
|
|
||||||
( MachineWord )
|
|
||||||
( Stream MachineSyllab )
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
let mut bytes = [0 as u8; 8];
|
|
||||||
f0.read_exact(&mut bytes).expect("");
|
|
||||||
let n = u64::from_le_bytes(bytes);
|
|
||||||
bytes = fib(n).to_le_bytes();
|
|
||||||
f1.write(&bytes).expect("");
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "int2str"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
nested = { path = "../../nested" }
|
|
|
@ -1,36 +0,0 @@
|
||||||
use std::{fs::File, io::Read, os::unix::io::FromRawFd};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
nested::magic_header();
|
|
||||||
eprintln!(" Human-readably Print MachineInt");
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
let mut f0 = unsafe { File::from_raw_fd(0) };
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
>0:
|
|
||||||
( ℕ )
|
|
||||||
( MachineInt )
|
|
||||||
( MachineWord )
|
|
||||||
( Stream MachineSyllab )
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
<1:
|
|
||||||
( ℕ )
|
|
||||||
( PositionalInt 10 BigEndian )
|
|
||||||
( Sequence ( Digit 10 ) )
|
|
||||||
( Sequence UTF-8-Char )
|
|
||||||
( Stream UTF-8-Char )
|
|
||||||
( Stream MachineSyllab )
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
let mut bytes = [0 as u8; 8];
|
|
||||||
f0.read_exact(&mut bytes).expect("");
|
|
||||||
println!("{}", u64::from_le_bytes(bytes));
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "radix_transform"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
nested = { path = "../../nested" }
|
|
||||||
|
|
||||||
[dependencies.async-std]
|
|
||||||
version = "1.9.0"
|
|
||||||
features = ["unstable", "attributes"]
|
|
|
@ -1,137 +0,0 @@
|
||||||
use nested::{
|
|
||||||
core::{TypeDict, ViewPort},
|
|
||||||
integer::RadixProjection,
|
|
||||||
vec::VecBuffer,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[async_std::main]
|
|
||||||
async fn main() {
|
|
||||||
let mut td = TypeDict::new();
|
|
||||||
for tn in vec![
|
|
||||||
"MachineWord",
|
|
||||||
"MachineInt",
|
|
||||||
"MachineSyllab",
|
|
||||||
"Vec",
|
|
||||||
"Stream",
|
|
||||||
"Json",
|
|
||||||
"Sequence",
|
|
||||||
"UTF-8-Char",
|
|
||||||
"PositionalInt",
|
|
||||||
"Digit",
|
|
||||||
"LittleEndian",
|
|
||||||
"BigEndian",
|
|
||||||
"DiffStream",
|
|
||||||
"ℕ",
|
|
||||||
"$src_radix",
|
|
||||||
"$dst_radix",
|
|
||||||
] {
|
|
||||||
td.add_typename(tn.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let radix_types = vec![
|
|
||||||
td.type_term_from_str("( ℕ )").unwrap(),
|
|
||||||
td.type_term_from_str("( PositionalInt 10 LittleEndian )")
|
|
||||||
.unwrap(),
|
|
||||||
td.type_term_from_str("( Sequence ( Digit 10 ) )").unwrap(),
|
|
||||||
td.type_term_from_str("( Sequence UTF-8-Char )").unwrap(),
|
|
||||||
td.type_term_from_str("( Sequence MachineSyllab )").unwrap(),
|
|
||||||
];
|
|
||||||
|
|
||||||
let src_types = vec![
|
|
||||||
td.type_term_from_str("( ℕ )").unwrap(),
|
|
||||||
td.type_term_from_str("( PositionalInt $src_radix LittleEndian )")
|
|
||||||
.unwrap(),
|
|
||||||
td.type_term_from_str("( Sequence ( Digit $src_radix ) )")
|
|
||||||
.unwrap(),
|
|
||||||
td.type_term_from_str("( Sequence MachineInt )").unwrap(),
|
|
||||||
td.type_term_from_str("( DiffStream ( Vec MachineInt ) )")
|
|
||||||
.unwrap(),
|
|
||||||
td.type_term_from_str("( Json )").unwrap(),
|
|
||||||
td.type_term_from_str("( Stream UTF-8-Char )").unwrap(),
|
|
||||||
td.type_term_from_str("( Stream MachineSyllab )").unwrap(),
|
|
||||||
];
|
|
||||||
|
|
||||||
let dst_types = vec![
|
|
||||||
td.type_term_from_str("( ℕ )").unwrap(),
|
|
||||||
td.type_term_from_str("( PositionalInt $dst_radix LittleEndian )")
|
|
||||||
.unwrap(),
|
|
||||||
td.type_term_from_str("( Sequence ( Digit $dst_radix ) )")
|
|
||||||
.unwrap(),
|
|
||||||
td.type_term_from_str("( Sequence MachineInt )").unwrap(),
|
|
||||||
td.type_term_from_str("( DiffStream ( Vec MachineInt ) )")
|
|
||||||
.unwrap(),
|
|
||||||
td.type_term_from_str("( Json )").unwrap(),
|
|
||||||
td.type_term_from_str("( Stream UTF-8-Char )").unwrap(),
|
|
||||||
td.type_term_from_str("( Stream MachineSyllab )").unwrap(),
|
|
||||||
];
|
|
||||||
|
|
||||||
nested::magic_header();
|
|
||||||
eprintln!(" Convert Radix of Positional Integer");
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
eprintln!("\n$1: src_radix");
|
|
||||||
for t in radix_types.iter() {
|
|
||||||
eprintln!(" {}", td.type_term_to_str(t));
|
|
||||||
}
|
|
||||||
|
|
||||||
eprintln!("\n$2: dst_radix");
|
|
||||||
for t in radix_types.iter() {
|
|
||||||
eprintln!(" {}", td.type_term_to_str(t));
|
|
||||||
}
|
|
||||||
|
|
||||||
eprintln!("\n>0: n");
|
|
||||||
for t in src_types.iter() {
|
|
||||||
eprintln!(" {}", td.type_term_to_str(t));
|
|
||||||
}
|
|
||||||
|
|
||||||
eprintln!("\n<1: n");
|
|
||||||
for t in dst_types.iter() {
|
|
||||||
eprintln!(" {}", td.type_term_to_str(t));
|
|
||||||
}
|
|
||||||
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
let mut args = std::env::args();
|
|
||||||
args.next().expect("Arg $0 missing!");
|
|
||||||
|
|
||||||
let src_radix_str = args.next().expect("Arg $1 required!");
|
|
||||||
let dst_radix_str = args.next().expect("Arg $2 required!");
|
|
||||||
|
|
||||||
let src_radix = usize::from_str_radix(&src_radix_str, 10).expect("could not parse src_radix");
|
|
||||||
let dst_radix = usize::from_str_radix(&dst_radix_str, 10).expect("could not parse dst_radix");
|
|
||||||
|
|
||||||
assert!(src_radix > 1);
|
|
||||||
assert!(dst_radix > 1);
|
|
||||||
|
|
||||||
let src_digits_port = ViewPort::new();
|
|
||||||
let dst_digits_port = ViewPort::new();
|
|
||||||
|
|
||||||
let mut src_digits = VecBuffer::<usize>::new(src_digits_port.inner());
|
|
||||||
|
|
||||||
let _proj = RadixProjection::new(
|
|
||||||
src_radix,
|
|
||||||
dst_radix,
|
|
||||||
src_digits_port.outer().to_sequence(),
|
|
||||||
dst_digits_port.inner(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// output dst digits
|
|
||||||
let writer = {
|
|
||||||
use std::os::unix::io::FromRawFd;
|
|
||||||
|
|
||||||
dst_digits_port
|
|
||||||
.outer()
|
|
||||||
.serialize_json(unsafe { std::fs::File::from_raw_fd(1) })
|
|
||||||
};
|
|
||||||
|
|
||||||
// start reading src digits
|
|
||||||
{
|
|
||||||
use async_std::os::unix::io::FromRawFd;
|
|
||||||
|
|
||||||
src_digits
|
|
||||||
.from_json(unsafe { async_std::fs::File::from_raw_fd(0) })
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
|
|
||||||
drop(writer);
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "str2int"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
nested = { path = "../../nested" }
|
|
|
@ -1,69 +0,0 @@
|
||||||
use std::{
|
|
||||||
fs::File,
|
|
||||||
io::{Read, Write},
|
|
||||||
os::unix::io::FromRawFd,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
nested::magic_header();
|
|
||||||
eprintln!(" Parse MachineInt from String");
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
$1: radix
|
|
||||||
( ℕ )
|
|
||||||
( PositionalInt 10 BigEndian )
|
|
||||||
( Sequence ( Digit 10 ) )
|
|
||||||
( Sequence UTF-8-Char )
|
|
||||||
( Sequence MachineSyllab )
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
>0: n
|
|
||||||
( ℕ )
|
|
||||||
( PositionalInt $radix BigEndian )
|
|
||||||
( Sequence ( Digit $radix ) )
|
|
||||||
( Sequence UTF-8-Char )
|
|
||||||
( Stream UTF-8-Char )
|
|
||||||
( Stream MachineSyllab )
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
eprintln!(
|
|
||||||
"
|
|
||||||
<1: n
|
|
||||||
( ℕ )
|
|
||||||
( MachineInt )
|
|
||||||
( MachineWord )
|
|
||||||
( Stream MachineSyllab )
|
|
||||||
"
|
|
||||||
);
|
|
||||||
|
|
||||||
nested::magic_header();
|
|
||||||
|
|
||||||
let mut f0 = unsafe { File::from_raw_fd(0) };
|
|
||||||
let mut f1 = unsafe { File::from_raw_fd(1) };
|
|
||||||
|
|
||||||
let mut args = std::env::args();
|
|
||||||
args.next().expect("Arg $0 missing!");
|
|
||||||
|
|
||||||
let radix_str = args.next().expect("Arg $1 required!");
|
|
||||||
|
|
||||||
let radix = u32::from_str_radix(&radix_str, 10).expect("could not parse radix");
|
|
||||||
if radix > 16 {
|
|
||||||
panic!("invalid radix! (radix<=16 required)");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut chars = Vec::new();
|
|
||||||
f0.read_to_end(&mut chars).expect("");
|
|
||||||
chars.retain(|c| (*c as char).is_alphanumeric());
|
|
||||||
f1.write(
|
|
||||||
&u64::from_str_radix(&String::from_utf8_lossy(&chars), radix)
|
|
||||||
.unwrap()
|
|
||||||
.to_le_bytes(),
|
|
||||||
)
|
|
||||||
.expect("");
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
|
|
||||||
pub mod list;
|
|
||||||
pub mod product;
|
|
||||||
pub mod sum;
|
|
||||||
|
|
||||||
pub mod char;
|
|
||||||
pub mod integer;
|
|
||||||
pub mod typeterm;
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
#![feature(trait_alias)]
|
|
||||||
|
|
||||||
pub mod terminal;
|
|
||||||
|
|
||||||
pub mod utils;
|
|
||||||
pub mod editors;
|
|
||||||
pub mod tree;
|
|
||||||
pub mod type_system;
|
|
||||||
|
|
||||||
pub mod diagnostics;
|
|
||||||
pub mod commander;
|
|
||||||
//pub mod product;
|
|
||||||
//pub mod sum;
|
|
||||||
//pub mod list;
|
|
||||||
|
|
||||||
pub fn magic_header() {
|
|
||||||
eprintln!("<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
pub trait StringGen {
|
|
||||||
fn get_string(&self) -> String;
|
|
||||||
}
|
|
||||||
|
|
||||||
use crate::{tree::{TreeNav}, diagnostics::Diagnostics, terminal::TerminalView, core::{OuterViewPort}};
|
|
||||||
*/
|
|
||||||
|
|
||||||
use r3vi::view::OuterViewPort;
|
|
||||||
use crate::terminal::TerminalView;
|
|
||||||
|
|
||||||
pub trait PtySegment {
|
|
||||||
fn pty_view(&self) -> OuterViewPort<dyn TerminalView>;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,331 +0,0 @@
|
||||||
#![feature(iter_advance_by)]
|
|
||||||
|
|
||||||
use {
|
|
||||||
cgmath::Point2,
|
|
||||||
nested::terminal::{TerminalAtom, TerminalStyle},
|
|
||||||
std::{
|
|
||||||
fs::File,
|
|
||||||
io::{stdin, Read, Write},
|
|
||||||
os::unix::io::FromRawFd,
|
|
||||||
},
|
|
||||||
vte::{Params, Parser, Perform},
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ColorPalett {
|
|
||||||
black: (u8, u8, u8),
|
|
||||||
red: (u8, u8, u8),
|
|
||||||
green: (u8, u8, u8),
|
|
||||||
yellow: (u8, u8, u8),
|
|
||||||
blue: (u8, u8, u8),
|
|
||||||
magenta: (u8, u8, u8),
|
|
||||||
cyan: (u8, u8, u8),
|
|
||||||
white: (u8, u8, u8),
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PerfAtom {
|
|
||||||
colors: ColorPalett,
|
|
||||||
term_width: i16,
|
|
||||||
|
|
||||||
cursor: Point2<i16>,
|
|
||||||
style: TerminalStyle,
|
|
||||||
|
|
||||||
out: File,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PerfAtom {
|
|
||||||
fn write_atom(&mut self, pos: Point2<i16>, atom: Option<TerminalAtom>) {
|
|
||||||
self.out
|
|
||||||
.write(&bincode::serialize(&(pos, atom)).unwrap())
|
|
||||||
.expect("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Perform for PerfAtom {
|
|
||||||
fn print(&mut self, c: char) {
|
|
||||||
//eprintln!("[print] {:?}", c);
|
|
||||||
self.write_atom(self.cursor, Some(TerminalAtom::new(c, self.style)));
|
|
||||||
|
|
||||||
self.cursor.x += 1;
|
|
||||||
if self.cursor.x > self.term_width {
|
|
||||||
self.cursor.x = 0;
|
|
||||||
self.cursor.y += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn execute(&mut self, byte: u8) {
|
|
||||||
//eprintln!("[execute] {:02x}", byte);
|
|
||||||
match byte {
|
|
||||||
b'\n' => {
|
|
||||||
self.cursor.x = 0;
|
|
||||||
self.cursor.y += 1;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hook(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
|
|
||||||
eprintln!(
|
|
||||||
"[hook] params={:?}, intermediates={:?}, ignore={:?}, char={:?}",
|
|
||||||
params, intermediates, ignore, c
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn put(&mut self, byte: u8) {
|
|
||||||
eprintln!("[put] {:02x}", byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unhook(&mut self) {
|
|
||||||
eprintln!("[unhook]");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) {
|
|
||||||
eprintln!(
|
|
||||||
"[osc_dispatch] params={:?} bell_terminated={}",
|
|
||||||
params, bell_terminated
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
|
|
||||||
eprintln!(
|
|
||||||
"[csi_dispatch] params={:#?}, intermediates={:?}, ignore={:?}, char={:?}",
|
|
||||||
params, intermediates, ignore, c
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut piter = params.into_iter();
|
|
||||||
|
|
||||||
match c {
|
|
||||||
// Set SGR
|
|
||||||
'm' => {
|
|
||||||
while let Some(n) = piter.next() {
|
|
||||||
match n[0] {
|
|
||||||
0 => self.style = TerminalStyle::default(),
|
|
||||||
1 => self.style = self.style.add(TerminalStyle::bold(true)),
|
|
||||||
3 => self.style = self.style.add(TerminalStyle::italic(true)),
|
|
||||||
4 => self.style = self.style.add(TerminalStyle::underline(true)),
|
|
||||||
|
|
||||||
30 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color(self.colors.black))
|
|
||||||
}
|
|
||||||
40 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color(self.colors.black))
|
|
||||||
}
|
|
||||||
31 => self.style = self.style.add(TerminalStyle::fg_color(self.colors.red)),
|
|
||||||
41 => self.style = self.style.add(TerminalStyle::bg_color(self.colors.red)),
|
|
||||||
32 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color(self.colors.green))
|
|
||||||
}
|
|
||||||
42 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color(self.colors.green))
|
|
||||||
}
|
|
||||||
33 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color(self.colors.yellow))
|
|
||||||
}
|
|
||||||
43 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color(self.colors.yellow))
|
|
||||||
}
|
|
||||||
34 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color(self.colors.blue))
|
|
||||||
}
|
|
||||||
44 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color(self.colors.blue))
|
|
||||||
}
|
|
||||||
35 => {
|
|
||||||
self.style =
|
|
||||||
self.style.add(TerminalStyle::fg_color(self.colors.magenta))
|
|
||||||
}
|
|
||||||
45 => {
|
|
||||||
self.style =
|
|
||||||
self.style.add(TerminalStyle::bg_color(self.colors.magenta))
|
|
||||||
}
|
|
||||||
36 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color(self.colors.cyan))
|
|
||||||
}
|
|
||||||
46 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color(self.colors.cyan))
|
|
||||||
}
|
|
||||||
37 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color(self.colors.white))
|
|
||||||
}
|
|
||||||
47 => {
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color(self.colors.white))
|
|
||||||
}
|
|
||||||
|
|
||||||
38 => {
|
|
||||||
let x = piter.next().unwrap();
|
|
||||||
match x[0] {
|
|
||||||
2 => {
|
|
||||||
let r = piter.next().unwrap();
|
|
||||||
let g = piter.next().unwrap();
|
|
||||||
let b = piter.next().unwrap();
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color((
|
|
||||||
r[0] as u8,
|
|
||||||
g[0] as u8,
|
|
||||||
b[30] as u8,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
5 => {
|
|
||||||
let v = piter.next().unwrap();
|
|
||||||
self.style = self.style.add(TerminalStyle::fg_color(
|
|
||||||
ansi_colours::rgb_from_ansi256(v[0] as u8),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
48 => {
|
|
||||||
let x = piter.next().unwrap();
|
|
||||||
match x[0] {
|
|
||||||
2 => {
|
|
||||||
let r = piter.next().unwrap();
|
|
||||||
let g = piter.next().unwrap();
|
|
||||||
let b = piter.next().unwrap();
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color((
|
|
||||||
r[0] as u8,
|
|
||||||
g[0] as u8,
|
|
||||||
b[30] as u8,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
5 => {
|
|
||||||
let v = piter.next().unwrap();
|
|
||||||
self.style = self.style.add(TerminalStyle::bg_color(
|
|
||||||
ansi_colours::rgb_from_ansi256(v[0] as u8),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
'H' => {
|
|
||||||
if let Some(y) = piter.next() {
|
|
||||||
self.cursor.y = y[0] as i16 - 1
|
|
||||||
};
|
|
||||||
if let Some(x) = piter.next() {
|
|
||||||
self.cursor.x = x[0] as i16 - 1
|
|
||||||
};
|
|
||||||
|
|
||||||
eprintln!("cursor at {:?}", self.cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
'A' => {
|
|
||||||
self.cursor.y -= piter.next().unwrap()[0] as i16;
|
|
||||||
}
|
|
||||||
'B' => {
|
|
||||||
self.cursor.y += piter.next().unwrap()[0] as i16;
|
|
||||||
}
|
|
||||||
'C' => {
|
|
||||||
self.cursor.x += piter.next().unwrap()[0] as i16;
|
|
||||||
}
|
|
||||||
'D' => {
|
|
||||||
self.cursor.x -= piter.next().unwrap()[0] as i16;
|
|
||||||
}
|
|
||||||
'E' => {
|
|
||||||
self.cursor.x = 0;
|
|
||||||
self.cursor.y += piter.next().unwrap()[0] as i16;
|
|
||||||
}
|
|
||||||
|
|
||||||
'J' => {
|
|
||||||
let x = piter.next().unwrap_or(&[0 as u16; 1]);
|
|
||||||
match x[0] {
|
|
||||||
0 => {}
|
|
||||||
1 => {}
|
|
||||||
2 => {
|
|
||||||
for y in 0..100 {
|
|
||||||
for x in 0..self.term_width {
|
|
||||||
self.write_atom(Point2::new(x, y), None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// invalid
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
'K' => {
|
|
||||||
let x = piter.next().unwrap();
|
|
||||||
match x[0] {
|
|
||||||
// clear cursor until end
|
|
||||||
0 => {
|
|
||||||
for x in self.cursor.x..self.term_width {
|
|
||||||
self.write_atom(Point2::new(x, self.cursor.y), None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear start until cursor
|
|
||||||
1 => {
|
|
||||||
for x in 0..self.cursor.x {
|
|
||||||
self.write_atom(Point2::new(x, self.cursor.y), None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear entire line
|
|
||||||
2 => {
|
|
||||||
for x in 0..self.term_width {
|
|
||||||
self.write_atom(Point2::new(x, self.cursor.y), None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// invalid
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) {
|
|
||||||
eprintln!(
|
|
||||||
"[esc_dispatch] intermediates={:?}, ignore={:?}, byte={:02x}",
|
|
||||||
intermediates, ignore, byte
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let input = stdin();
|
|
||||||
let mut handle = input.lock();
|
|
||||||
|
|
||||||
let mut statemachine = Parser::new();
|
|
||||||
let mut performer = PerfAtom {
|
|
||||||
cursor: Point2::new(0, 0),
|
|
||||||
style: TerminalStyle::default(),
|
|
||||||
term_width: 200,
|
|
||||||
out: unsafe { File::from_raw_fd(1) },
|
|
||||||
|
|
||||||
colors: ColorPalett {
|
|
||||||
black: (1, 1, 1),
|
|
||||||
red: (222, 56, 43),
|
|
||||||
green: (0, 64, 0),
|
|
||||||
yellow: (255, 199, 6),
|
|
||||||
blue: (0, 111, 184),
|
|
||||||
magenta: (118, 38, 113),
|
|
||||||
cyan: (44, 181, 233),
|
|
||||||
white: (204, 204, 204),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut buf = [0; 2048];
|
|
||||||
|
|
||||||
loop {
|
|
||||||
match handle.read(&mut buf) {
|
|
||||||
Ok(0) => break,
|
|
||||||
Ok(n) => {
|
|
||||||
for byte in &buf[..n] {
|
|
||||||
statemachine.advance(&mut performer, *byte);
|
|
||||||
performer.out.flush().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
println!("err: {}", err);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
[package]
|
|
||||||
authors = ["Michael Sippel <micha@fragmental.art>"]
|
|
||||||
name = "display_server"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
nested = { path = "../../nested" }
|
|
||||||
termion = "1.5.5"
|
|
||||||
cgmath = { version = "0.18.0", features = ["serde"] }
|
|
||||||
serde = { version = "1.0", features = ["serde_derive"] }
|
|
||||||
bincode = "1.3.3"
|
|
|
@ -1,67 +0,0 @@
|
||||||
use {
|
|
||||||
cgmath::{Point2, Vector2},
|
|
||||||
nested::terminal::{TerminalAtom, TerminalStyle},
|
|
||||||
std::io::{stdout, Read, Write},
|
|
||||||
termion::raw::IntoRawMode,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut out = stdout().into_raw_mode().unwrap();
|
|
||||||
write!(
|
|
||||||
out,
|
|
||||||
"{}{}{}",
|
|
||||||
termion::cursor::Hide,
|
|
||||||
termion::cursor::Goto(1, 1),
|
|
||||||
termion::style::Reset
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut cur_pos = Point2::<i16>::new(0, 0);
|
|
||||||
let mut cur_style = TerminalStyle::default();
|
|
||||||
|
|
||||||
let mut input = std::io::stdin();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
match bincode::deserialize_from::<_, (Point2<i16>, Option<TerminalAtom>)>(input.by_ref()) {
|
|
||||||
Ok((pos, atom)) => {
|
|
||||||
if pos != cur_pos {
|
|
||||||
write!(
|
|
||||||
out,
|
|
||||||
"{}",
|
|
||||||
termion::cursor::Goto(pos.x as u16 + 1, pos.y as u16 + 1)
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(atom) = atom {
|
|
||||||
if cur_style != atom.style {
|
|
||||||
cur_style = atom.style;
|
|
||||||
write!(out, "{}", atom.style).expect("");
|
|
||||||
}
|
|
||||||
|
|
||||||
write!(out, "{}", atom.c.unwrap_or(' ')).expect("");
|
|
||||||
} else {
|
|
||||||
write!(out, "{} ", termion::style::Reset).expect("");
|
|
||||||
cur_style = TerminalStyle::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_pos = pos + Vector2::new(1, 0);
|
|
||||||
|
|
||||||
out.flush().unwrap();
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
match *err {
|
|
||||||
bincode::ErrorKind::Io(_io_error) => break,
|
|
||||||
err => {
|
|
||||||
eprintln!("deserialization error\n{:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore conventional terminal settings
|
|
||||||
write!(out, "{}", termion::cursor::Show).unwrap();
|
|
||||||
out.flush().unwrap();
|
|
||||||
}
|
|
Loading…
Reference in a new issue