pty list: add split key
This commit is contained in:
parent
b2f437d7df
commit
273f20d3db
8 changed files with 87 additions and 7 deletions
|
@ -115,6 +115,7 @@ impl PosIntEditor {
|
||||||
digits_editor: PTYListEditor::new(
|
digits_editor: PTYListEditor::new(
|
||||||
Box::new(move || Arc::new(RwLock::new(DigitEditor::new(radix)))) as Box<dyn Fn() -> Arc<RwLock<DigitEditor>> + Send + Sync>,
|
Box::new(move || Arc::new(RwLock::new(DigitEditor::new(radix)))) as Box<dyn Fn() -> Arc<RwLock<DigitEditor>> + Send + Sync>,
|
||||||
SeqDecorStyle::Hex,
|
SeqDecorStyle::Hex,
|
||||||
|
' ',
|
||||||
0
|
0
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,20 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// split the list off at the current cursor position and return the second half
|
||||||
|
/*
|
||||||
|
pub fn split(&mut self) -> ListEditor<ItemEditor> {
|
||||||
|
let mut le = ListEditor::new(self.make_item_editor.clone());
|
||||||
|
let p = self.cursor.get();
|
||||||
|
for i in p.idx .. self.data.len() {
|
||||||
|
le.data.push( self.data[p.idx] );
|
||||||
|
self.data.remove(p.idx);
|
||||||
|
}
|
||||||
|
le.goto(TreeCursor::home());
|
||||||
|
le
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.data.clear();
|
self.data.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
||||||
{
|
{
|
||||||
pub editor: ListEditor<ItemEditor>,
|
pub editor: ListEditor<ItemEditor>,
|
||||||
|
|
||||||
|
split_char: char,
|
||||||
|
|
||||||
style: SeqDecorStyle,
|
style: SeqDecorStyle,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
|
|
||||||
|
@ -39,6 +41,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
||||||
pub fn new(
|
pub fn new(
|
||||||
make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static,
|
make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static,
|
||||||
style: SeqDecorStyle,
|
style: SeqDecorStyle,
|
||||||
|
split_char: char,
|
||||||
depth: usize
|
depth: usize
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let port = ViewPort::new();
|
let port = ViewPort::new();
|
||||||
|
@ -46,6 +49,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
||||||
editor: ListEditor::new(make_item_editor, depth),
|
editor: ListEditor::new(make_item_editor, depth),
|
||||||
style,
|
style,
|
||||||
depth,
|
depth,
|
||||||
|
split_char,
|
||||||
port
|
port
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,11 +57,13 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
||||||
pub fn from_editor(
|
pub fn from_editor(
|
||||||
editor: ListEditor<ItemEditor>,
|
editor: ListEditor<ItemEditor>,
|
||||||
style: SeqDecorStyle,
|
style: SeqDecorStyle,
|
||||||
|
split_char: char,
|
||||||
depth: usize
|
depth: usize
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let port = ViewPort::new();
|
let port = ViewPort::new();
|
||||||
PTYListEditor {
|
PTYListEditor {
|
||||||
editor,
|
editor,
|
||||||
|
split_char,
|
||||||
style,
|
style,
|
||||||
depth,
|
depth,
|
||||||
port
|
port
|
||||||
|
@ -158,6 +164,32 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
||||||
self.editor.set_leaf_mode(ListCursorMode::Insert);
|
self.editor.set_leaf_mode(ListCursorMode::Insert);
|
||||||
TerminalEditorResult::Continue
|
TerminalEditorResult::Continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
|
||||||
|
if *c == self.split_char {
|
||||||
|
let c = self.editor.cursor.get();
|
||||||
|
self.editor.goto(TreeCursor::none());
|
||||||
|
self.editor.cursor.set(ListCursor {
|
||||||
|
mode: ListCursorMode::Insert,
|
||||||
|
idx: Some(1 + c.idx.unwrap_or(0))
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if let Some(e) = self.editor.get_item() {
|
||||||
|
match e.write().unwrap().handle_terminal_event(&TerminalEvent::Input(Event::Key(Key::Char(*c)))) {
|
||||||
|
TerminalEditorResult::Exit => {
|
||||||
|
self.editor.cursor.set(ListCursor {
|
||||||
|
mode: ListCursorMode::Insert,
|
||||||
|
idx: Some(idx as isize + 1),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
TerminalEditorResult::Continue => {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TerminalEditorResult::Continue
|
||||||
|
}
|
||||||
ev => {
|
ev => {
|
||||||
if let Some(e) = self.editor.get_item() {
|
if let Some(e) = self.editor.get_item() {
|
||||||
match e.write().unwrap().handle_terminal_event(ev) {
|
match e.write().unwrap().handle_terminal_event(ev) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
Arc::new(RwLock::new(CharEditor::new()))
|
Arc::new(RwLock::new(CharEditor::new()))
|
||||||
}),
|
}),
|
||||||
SeqDecorStyle::DoubleQuote,
|
SeqDecorStyle::DoubleQuote,
|
||||||
|
'"',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
@ -48,6 +49,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
SeqDecorStyle::EnumSet,
|
SeqDecorStyle::EnumSet,
|
||||||
|
'"',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
@ -59,6 +61,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
|| { Arc::new(RwLock::new(CharEditor::new())) }
|
|| { Arc::new(RwLock::new(CharEditor::new())) }
|
||||||
),
|
),
|
||||||
SeqDecorStyle::Plain,
|
SeqDecorStyle::Plain,
|
||||||
|
'\n',
|
||||||
depth+1
|
depth+1
|
||||||
)
|
)
|
||||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
@ -70,6 +73,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
Arc::new(RwLock::new(PosIntEditor::new(16)))
|
Arc::new(RwLock::new(PosIntEditor::new(16)))
|
||||||
}),
|
}),
|
||||||
SeqDecorStyle::EnumSet,
|
SeqDecorStyle::EnumSet,
|
||||||
|
',',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
@ -84,10 +88,12 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
Arc::new(RwLock::new(CharEditor::new()))
|
Arc::new(RwLock::new(CharEditor::new()))
|
||||||
}),
|
}),
|
||||||
SeqDecorStyle::Plain,
|
SeqDecorStyle::Plain,
|
||||||
|
'\n',
|
||||||
d
|
d
|
||||||
)))
|
)))
|
||||||
}}),
|
}}),
|
||||||
SeqDecorStyle::Path,
|
SeqDecorStyle::Path,
|
||||||
|
'/',
|
||||||
depth
|
depth
|
||||||
))) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
))) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
|
||||||
|
@ -106,6 +112,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
SeqDecorStyle::EnumSet,
|
SeqDecorStyle::EnumSet,
|
||||||
|
',',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
@ -121,6 +128,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
SeqDecorStyle::VerticalSexpr,
|
SeqDecorStyle::VerticalSexpr,
|
||||||
|
',',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
@ -163,6 +171,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
SeqDecorStyle::VerticalSexpr,
|
SeqDecorStyle::VerticalSexpr,
|
||||||
|
'\n',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
@ -177,6 +186,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
SeqDecorStyle::Tuple,
|
SeqDecorStyle::Tuple,
|
||||||
|
'\n',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
@ -188,6 +198,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
||||||
Arc::new(RwLock::new(CharEditor::new()))
|
Arc::new(RwLock::new(CharEditor::new()))
|
||||||
},
|
},
|
||||||
SeqDecorStyle::DoubleQuote,
|
SeqDecorStyle::DoubleQuote,
|
||||||
|
' ',
|
||||||
depth
|
depth
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
|
@ -93,6 +93,21 @@ impl Action for ActNum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ActColor {}
|
||||||
|
impl Action for ActColor {
|
||||||
|
fn make_editor(&self, ctx: Arc<RwLock<Context>>) -> Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>> {
|
||||||
|
let depth = 1;
|
||||||
|
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
|
||||||
|
.with_t(Point2::new(1, 1), " RGB")
|
||||||
|
.with_n(Point2::new(0, 1), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] )
|
||||||
|
.with_t(Point2::new(1, 2), " HSV")
|
||||||
|
.with_n(Point2::new(0, 2), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] )
|
||||||
|
.with_t(Point2::new(1, 3), " HSL")
|
||||||
|
.with_n(Point2::new(0, 3), vec![ ctx.read().unwrap().type_term_from_str("( RGB )").unwrap() ] )
|
||||||
|
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Commander {
|
pub struct Commander {
|
||||||
ctx: Arc<RwLock<Context>>,
|
ctx: Arc<RwLock<Context>>,
|
||||||
cmds: HashMap<String, Arc<dyn Action + Send + Sync>>,
|
cmds: HashMap<String, Arc<dyn Action + Send + Sync>>,
|
||||||
|
@ -119,6 +134,7 @@ impl Commander {
|
||||||
Arc::new(RwLock::new(CharEditor::new()))
|
Arc::new(RwLock::new(CharEditor::new()))
|
||||||
},
|
},
|
||||||
SeqDecorStyle::Plain,
|
SeqDecorStyle::Plain,
|
||||||
|
'\n',
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -144,6 +160,7 @@ impl Commander {
|
||||||
cmds.insert("ls".into(), Arc::new(ActLs{}) as Arc<dyn Action + Send + Sync>);
|
cmds.insert("ls".into(), Arc::new(ActLs{}) as Arc<dyn Action + Send + Sync>);
|
||||||
cmds.insert("cp".into(), Arc::new(ActCp{}) as Arc<dyn Action + Send + Sync>);
|
cmds.insert("cp".into(), Arc::new(ActCp{}) as Arc<dyn Action + Send + Sync>);
|
||||||
cmds.insert("num".into(), Arc::new(ActNum{}) as Arc<dyn Action + Send + Sync>);
|
cmds.insert("num".into(), Arc::new(ActNum{}) as Arc<dyn Action + Send + Sync>);
|
||||||
|
cmds.insert("color".into(), Arc::new(ActColor{}) as Arc<dyn Action + Send + Sync>);
|
||||||
|
|
||||||
let m_buf = VecBuffer::new();
|
let m_buf = VecBuffer::new();
|
||||||
let mut c = Commander {
|
let mut c = Commander {
|
||||||
|
|
|
@ -80,6 +80,7 @@ async fn main() {
|
||||||
)}),
|
)}),
|
||||||
*/
|
*/
|
||||||
SeqDecorStyle::VerticalSexpr,
|
SeqDecorStyle::VerticalSexpr,
|
||||||
|
'\n',
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -153,6 +154,8 @@ async fn main() {
|
||||||
for x in entry.addr.iter() {
|
for x in entry.addr.iter() {
|
||||||
b.push(
|
b.push(
|
||||||
make_label(&format!("{}", x))
|
make_label(&format!("{}", x))
|
||||||
|
.map_item(|p,a| a
|
||||||
|
.add_style_back(TerminalStyle::fg_color((0, 100, 20))))
|
||||||
);
|
);
|
||||||
b.push(
|
b.push(
|
||||||
make_label(".")
|
make_label(".")
|
||||||
|
@ -206,7 +209,7 @@ async fn main() {
|
||||||
if cur.tree_addr.len() > 0 {
|
if cur.tree_addr.len() > 0 {
|
||||||
status_chars.push(TerminalAtom::new(
|
status_chars.push(TerminalAtom::new(
|
||||||
'@',
|
'@',
|
||||||
TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)),
|
TerminalStyle::fg_color((150, 80,230)).add(TerminalStyle::bold(true)),
|
||||||
));
|
));
|
||||||
for x in cur.tree_addr {
|
for x in cur.tree_addr {
|
||||||
for c in format!("{}", x).chars() {
|
for c in format!("{}", x).chars() {
|
||||||
|
@ -215,13 +218,13 @@ async fn main() {
|
||||||
}
|
}
|
||||||
status_chars.push(TerminalAtom::new(
|
status_chars.push(TerminalAtom::new(
|
||||||
'.',
|
'.',
|
||||||
TerminalStyle::fg_color((120, 80, 80)),
|
TerminalStyle::fg_color((150, 80,230))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
status_chars.push(TerminalAtom::new(
|
status_chars.push(TerminalAtom::new(
|
||||||
':',
|
':',
|
||||||
TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)),
|
TerminalStyle::fg_color((150, 80,230)).add(TerminalStyle::bold(true)),
|
||||||
));
|
));
|
||||||
for c in match cur.leaf_mode {
|
for c in match cur.leaf_mode {
|
||||||
ListCursorMode::Insert => "INSERT",
|
ListCursorMode::Insert => "INSERT",
|
||||||
|
@ -236,7 +239,7 @@ async fn main() {
|
||||||
}
|
}
|
||||||
status_chars.push(TerminalAtom::new(
|
status_chars.push(TerminalAtom::new(
|
||||||
':',
|
':',
|
||||||
TerminalStyle::fg_color((120, 80, 80)).add(TerminalStyle::bold(true)),
|
TerminalStyle::fg_color((150, 80,230)).add(TerminalStyle::bold(true)),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
for c in "Press <DN> to enter".chars() {
|
for c in "Press <DN> to enter".chars() {
|
||||||
|
|
|
@ -106,11 +106,13 @@ impl ProcessLauncher {
|
||||||
editor: PTYListEditor::new(
|
editor: PTYListEditor::new(
|
||||||
Box::new(|| Arc::new(RwLock::new(CharEditor::new()))),
|
Box::new(|| Arc::new(RwLock::new(CharEditor::new()))),
|
||||||
SeqDecorStyle::Plain,
|
SeqDecorStyle::Plain,
|
||||||
|
'\n',
|
||||||
1
|
1
|
||||||
),
|
),
|
||||||
}))
|
}))
|
||||||
}) as Box<dyn Fn() -> Arc<RwLock<ProcessArg>> + Send + Sync>,
|
}) as Box<dyn Fn() -> Arc<RwLock<ProcessArg>> + Send + Sync>,
|
||||||
SeqDecorStyle::HorizontalSexpr,
|
SeqDecorStyle::HorizontalSexpr,
|
||||||
|
' ',
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue