2022-05-08 23:30:49 +02:00
|
|
|
use {
|
|
|
|
crate::{
|
2022-06-19 23:13:21 +02:00
|
|
|
core::{OuterViewPort, TypeLadder, Context},
|
2022-05-08 23:30:49 +02:00
|
|
|
terminal::{
|
2022-06-19 23:13:21 +02:00
|
|
|
TerminalEditor, TerminalStyle, TerminalView,
|
2022-05-08 23:30:49 +02:00
|
|
|
make_label
|
|
|
|
},
|
2022-06-19 23:13:21 +02:00
|
|
|
tree_nav::{TerminalTreeEditor},
|
|
|
|
color::{bg_style_from_depth, fg_style_from_depth}
|
2022-05-08 23:30:49 +02:00
|
|
|
},
|
|
|
|
std::{sync::{Arc, RwLock}, ops::{Deref, DerefMut}},
|
|
|
|
termion::event::{Event, Key},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
2022-06-24 15:54:05 +02:00
|
|
|
pub enum ProductEditorSegment {
|
2022-06-19 23:13:21 +02:00
|
|
|
T( String, usize ),
|
2022-05-08 23:30:49 +02:00
|
|
|
N {
|
|
|
|
t: TypeLadder,
|
|
|
|
editor: Option<Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>>,
|
2022-06-19 23:13:21 +02:00
|
|
|
cur_depth: usize
|
2022-05-08 23:30:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-24 15:54:05 +02:00
|
|
|
impl ProductEditorSegment {
|
2022-05-08 23:30:49 +02:00
|
|
|
pub fn get_view(&self, ctx: Arc<RwLock<Context>>) -> OuterViewPort<dyn TerminalView> {
|
|
|
|
match self {
|
2022-06-24 15:54:05 +02:00
|
|
|
ProductEditorSegment::T(t, depth) =>
|
2022-05-08 23:30:49 +02:00
|
|
|
make_label(t.as_str())
|
2022-06-19 23:13:21 +02:00
|
|
|
.map_item({
|
|
|
|
let depth = *depth;
|
|
|
|
move |i, x|
|
|
|
|
x.add_style_back(fg_style_from_depth(depth))
|
|
|
|
}
|
|
|
|
),
|
2022-05-08 23:30:49 +02:00
|
|
|
|
2022-06-24 15:54:05 +02:00
|
|
|
ProductEditorSegment::N { t: _, editor: Some(e), cur_depth } =>
|
2022-05-08 23:30:49 +02:00
|
|
|
e.read().unwrap()
|
|
|
|
.get_term_view()
|
2022-08-12 18:57:40 +02:00
|
|
|
.map_item({
|
|
|
|
let e = e.clone();
|
|
|
|
move |i, x| {
|
|
|
|
let cur_depth = e.read().unwrap().get_cursor().tree_addr.len();
|
|
|
|
x
|
2022-06-19 23:13:21 +02:00
|
|
|
.add_style_back(fg_style_from_depth(cur_depth))//fg_color((250,210,0)))
|
|
|
|
.add_style_back(bg_style_from_depth(cur_depth))
|
2022-08-12 18:57:40 +02:00
|
|
|
}
|
2022-05-08 23:30:49 +02:00
|
|
|
}),
|
|
|
|
|
2022-06-24 15:54:05 +02:00
|
|
|
ProductEditorSegment::N{ t, editor: None, cur_depth } =>
|
2022-05-08 23:30:49 +02:00
|
|
|
make_label(&ctx.read().unwrap().type_term_to_str(&t[0]))
|
2022-06-19 23:13:21 +02:00
|
|
|
.map_item({
|
2022-08-12 18:57:40 +02:00
|
|
|
let cur_depth = 0;
|
2022-06-19 23:13:21 +02:00
|
|
|
move |i, x| x
|
2022-05-08 23:30:49 +02:00
|
|
|
.add_style_back(TerminalStyle::fg_color((130,90,40)))
|
2022-06-19 23:13:21 +02:00
|
|
|
.add_style_back(bg_style_from_depth(cur_depth))
|
2022-05-08 23:30:49 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|