list editor: refactor cursor handling
This commit is contained in:
parent
9905a2376f
commit
2563e06000
5 changed files with 632 additions and 377 deletions
35
nested/src/list/cursor.rs
Normal file
35
nested/src/list/cursor.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
pub enum ListCursorMode {
|
||||
Insert,
|
||||
Select,
|
||||
Modify
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
pub struct ListCursor {
|
||||
pub mode: ListCursorMode,
|
||||
pub idx: usize
|
||||
}
|
||||
|
||||
impl Default for ListCursor {
|
||||
fn default() -> Self {
|
||||
ListCursor {
|
||||
mode: ListCursorMode::Insert,
|
||||
idx: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub trait ListNav {
|
||||
fn pxev(&mut self) -> ListNavResult;
|
||||
fn nexd(&mut self) -> ListNavResult;
|
||||
fn pua(&mut self) -> ListNavResult;
|
||||
fn end(&mut self) -> ListNavResult;
|
||||
|
||||
fn set_cursor(&mut self, new_cursor: Option<ListCursor>) -> ListNavResult;
|
||||
fn get_cursor(&self) -> Option<ListCursor>;
|
||||
}
|
||||
*/
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,9 @@
|
|||
|
||||
pub mod editor;
|
||||
pub mod sexpr;
|
||||
pub mod cursor;
|
||||
pub mod editor;
|
||||
|
||||
pub use editor::{ListEditor, ListEditorStyle};
|
||||
pub use sexpr::{SExprView, ListDecoration};
|
||||
pub use cursor::{ListCursorMode, ListCursor};
|
||||
pub use editor::{ListEditor, ListEditorStyle};
|
||||
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
|
||||
#[derive(Eq, PartialEq)]
|
||||
use crate::list::ListCursorMode;
|
||||
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
pub enum TreeNavResult {
|
||||
Continue,
|
||||
Exit
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct TreeCursor {
|
||||
pub leaf_mode: ListCursorMode,
|
||||
pub tree_addr: Vec<usize>
|
||||
}
|
||||
|
||||
pub trait TreeNav {
|
||||
fn up(&mut self) -> TreeNavResult {
|
||||
TreeNavResult::Exit
|
||||
|
@ -30,11 +38,11 @@ pub trait TreeNav {
|
|||
TreeNavResult::Exit
|
||||
}
|
||||
|
||||
fn goto(&mut self, tree_addr: Vec<usize>) -> TreeNavResult {
|
||||
fn goto(&mut self, new_cursor: Option<TreeCursor>) -> TreeNavResult {
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
|
||||
fn get_cursor(&self) -> Option<Vec<usize>> {
|
||||
fn get_cursor(&self) -> Option<TreeCursor> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ use{
|
|||
TerminalEditor},
|
||||
string_editor::{CharEditor},
|
||||
tree_nav::{TreeNav, TreeNavResult, TerminalTreeEditor},
|
||||
list::{SExprView, ListEditor, ListEditorStyle}
|
||||
list::{SExprView, ListCursorMode, ListEditor, ListEditorStyle}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -261,17 +261,26 @@ write::
|
|||
}
|
||||
|
||||
status_chars.clear();
|
||||
match te.get_cursor() {
|
||||
Some(addr) => {
|
||||
status_chars.push(TerminalAtom::new('@', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
|
||||
for x in addr {
|
||||
for c in format!("{}", x).chars() {
|
||||
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((0, 100, 20))));
|
||||
}
|
||||
status_chars.push(TerminalAtom::new('.', TerminalStyle::fg_color((120, 80, 80))));
|
||||
if let Some(cur) = te.get_cursor() {
|
||||
status_chars.push(TerminalAtom::new('@', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
|
||||
for x in cur.tree_addr {
|
||||
for c in format!("{}", x).chars() {
|
||||
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((0, 100, 20))));
|
||||
}
|
||||
status_chars.push(TerminalAtom::new('.', TerminalStyle::fg_color((120, 80, 80))));
|
||||
}
|
||||
None => {}
|
||||
|
||||
status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
|
||||
for c in
|
||||
match cur.leaf_mode {
|
||||
ListCursorMode::Insert => "INSERT",
|
||||
ListCursorMode::Select => "SELECT",
|
||||
ListCursorMode::Modify => "MODIFY"
|
||||
}.chars()
|
||||
{
|
||||
status_chars.push(TerminalAtom::new(c, TerminalStyle::fg_color((200, 200, 20))));
|
||||
}
|
||||
status_chars.push(TerminalAtom::new(':', TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue