2022-06-19 23:13:21 +02:00
|
|
|
use {
|
|
|
|
crate::list::ListCursorMode,
|
2022-11-13 15:26:25 +01:00
|
|
|
crate::tree::TreeCursor,
|
2023-01-07 04:37:44 +01:00
|
|
|
crate::vec::VecBuffer,
|
|
|
|
crate::core::{OuterViewPort},
|
|
|
|
crate::sequence::{SequenceView, decorator::Separate},
|
|
|
|
crate::singleton::{SingletonBuffer, SingletonView},
|
|
|
|
cgmath::Vector2,
|
|
|
|
crate::{
|
|
|
|
terminal::{TerminalView, TerminalStyle, make_label}
|
|
|
|
|
|
|
|
}
|
2022-06-19 23:13:21 +02:00
|
|
|
};
|
2021-08-23 05:00:57 +02:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
2021-08-15 04:27:09 +02:00
|
|
|
pub enum TreeNavResult {
|
|
|
|
Continue,
|
2021-11-19 12:19:52 +01:00
|
|
|
Exit,
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2022-05-08 23:30:49 +02:00
|
|
|
|
2021-08-26 08:20:51 +02:00
|
|
|
/*
|
|
|
|
impl From<TreeNavResult> for TerminalEditorResult {
|
|
|
|
fn from(v: TreeNavResult) -> TerminalEditorResult {
|
|
|
|
match v {
|
|
|
|
TreeNavResult::Continue => TerminalEditorResult::Continue,
|
|
|
|
TreeNavResult::Exit => TerminalEditorResult::Exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-08 23:30:49 +02:00
|
|
|
*/
|
|
|
|
|
2023-01-07 04:37:44 +01:00
|
|
|
|
|
|
|
|
2021-08-15 04:27:09 +02:00
|
|
|
pub trait TreeNav {
|
2022-06-19 23:13:21 +02:00
|
|
|
/* CORE
|
|
|
|
*/
|
|
|
|
fn get_cursor(&self) -> TreeCursor {
|
|
|
|
TreeCursor::default()
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 04:37:44 +01:00
|
|
|
fn get_addr_view(&self) -> OuterViewPort<dyn SequenceView<Item = isize>> {
|
|
|
|
VecBuffer::<isize>::new().get_port().to_sequence()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_mode_view(&self) -> OuterViewPort<dyn SingletonView<Item = ListCursorMode>> {
|
|
|
|
SingletonBuffer::new(ListCursorMode::Select).get_port()
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn get_cursor_warp(&self) -> TreeCursor {
|
|
|
|
TreeCursor::default()
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2022-11-13 15:26:25 +01:00
|
|
|
fn get_max_depth(&self) -> usize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
2022-12-18 01:39:01 +01:00
|
|
|
fn goby(&mut self, _direction: Vector2<isize>) -> TreeNavResult {
|
2021-08-15 04:27:09 +02:00
|
|
|
TreeNavResult::Exit
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn goto(&mut self, _new_cursor: TreeCursor) -> TreeNavResult {
|
2021-08-15 04:27:09 +02:00
|
|
|
TreeNavResult::Exit
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
/* HULL
|
|
|
|
*/
|
|
|
|
fn set_addr(&mut self, addr: isize) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
c.tree_addr[0] = addr;
|
|
|
|
self.goto(c)
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn set_leaf_mode(&mut self, new_leaf_mode: ListCursorMode) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
c.leaf_mode = new_leaf_mode;
|
|
|
|
self.goto(c)
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn up(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(0, -1))
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
fn dn(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(0, 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pxev(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(-1, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn nexd(&mut self) -> TreeNavResult {
|
|
|
|
self.goby(Vector2::new(1, 0))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
fn qpxev(&mut self) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor();
|
|
|
|
match c.tree_addr.len() {
|
|
|
|
0 => {
|
|
|
|
self.goto(TreeCursor::home())
|
|
|
|
},
|
|
|
|
depth => {
|
|
|
|
if c.tree_addr[depth-1] != 0 {
|
|
|
|
c.tree_addr[depth-1] = 0;
|
|
|
|
} else {
|
|
|
|
for i in (0..depth-1).rev() {
|
|
|
|
if c.tree_addr[i] == 0 {
|
|
|
|
c.tree_addr[i] = -1;
|
|
|
|
} else {
|
|
|
|
c.tree_addr[i] -=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.goto(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn qnexd(&mut self) -> TreeNavResult {
|
|
|
|
let mut c = self.get_cursor_warp();
|
|
|
|
match c.tree_addr.len() {
|
|
|
|
0 => {
|
|
|
|
TreeNavResult::Exit
|
|
|
|
},
|
|
|
|
depth => {
|
|
|
|
if c.tree_addr[depth-1] != -1 {
|
|
|
|
c.tree_addr[depth-1] = -1;
|
|
|
|
} else {
|
|
|
|
for i in (0..depth-1).rev() {
|
|
|
|
if c.tree_addr[i] == -1 {
|
|
|
|
c.tree_addr[i] = 0;
|
|
|
|
} else {
|
|
|
|
c.tree_addr[i] += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-07 04:37:44 +01:00
|
|
|
|
2022-06-19 23:13:21 +02:00
|
|
|
self.goto(c)
|
|
|
|
}
|
|
|
|
}
|
2021-08-16 00:10:25 +02:00
|
|
|
}
|
2023-01-07 04:37:44 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
2021-08-15 04:27:09 +02:00
|
|
|
}
|
|
|
|
|