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(
|
||||
Box::new(move || Arc::new(RwLock::new(DigitEditor::new(radix)))) as Box<dyn Fn() -> Arc<RwLock<DigitEditor>> + Send + Sync>,
|
||||
SeqDecorStyle::Hex,
|
||||
' ',
|
||||
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) {
|
||||
self.data.clear();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
{
|
||||
pub editor: ListEditor<ItemEditor>,
|
||||
|
||||
split_char: char,
|
||||
|
||||
style: SeqDecorStyle,
|
||||
depth: usize,
|
||||
|
||||
|
@ -39,6 +41,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
pub fn new(
|
||||
make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static,
|
||||
style: SeqDecorStyle,
|
||||
split_char: char,
|
||||
depth: usize
|
||||
) -> Self {
|
||||
let port = ViewPort::new();
|
||||
|
@ -46,6 +49,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
editor: ListEditor::new(make_item_editor, depth),
|
||||
style,
|
||||
depth,
|
||||
split_char,
|
||||
port
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +57,13 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
pub fn from_editor(
|
||||
editor: ListEditor<ItemEditor>,
|
||||
style: SeqDecorStyle,
|
||||
split_char: char,
|
||||
depth: usize
|
||||
) -> Self {
|
||||
let port = ViewPort::new();
|
||||
PTYListEditor {
|
||||
editor,
|
||||
split_char,
|
||||
style,
|
||||
depth,
|
||||
port
|
||||
|
@ -158,6 +164,32 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
self.editor.set_leaf_mode(ListCursorMode::Insert);
|
||||
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 => {
|
||||
if let Some(e) = self.editor.get_item() {
|
||||
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()))
|
||||
}),
|
||||
SeqDecorStyle::DoubleQuote,
|
||||
'"',
|
||||
depth
|
||||
)
|
||||
))
|
||||
|
@ -48,6 +49,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
}
|
||||
}),
|
||||
SeqDecorStyle::EnumSet,
|
||||
'"',
|
||||
depth
|
||||
)
|
||||
)) 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())) }
|
||||
),
|
||||
SeqDecorStyle::Plain,
|
||||
'\n',
|
||||
depth+1
|
||||
)
|
||||
)) 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)))
|
||||
}),
|
||||
SeqDecorStyle::EnumSet,
|
||||
',',
|
||||
depth
|
||||
)
|
||||
)) 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()))
|
||||
}),
|
||||
SeqDecorStyle::Plain,
|
||||
'\n',
|
||||
d
|
||||
)))
|
||||
}}),
|
||||
SeqDecorStyle::Path,
|
||||
'/',
|
||||
depth
|
||||
))) 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,
|
||||
',',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
@ -121,20 +128,21 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
})
|
||||
},
|
||||
SeqDecorStyle::VerticalSexpr,
|
||||
',',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( RGB )").unwrap() {
|
||||
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
|
||||
.with_t(Point2::new(0, 0), "{")
|
||||
.with_t(Point2::new(0, 0), "{ ")
|
||||
.with_t(Point2::new(1, 1), "r: ")
|
||||
.with_n(Point2::new(2, 1), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
|
||||
.with_t(Point2::new(1, 2), "g: ")
|
||||
.with_n(Point2::new(2, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
|
||||
.with_t(Point2::new(1, 3), "b: ")
|
||||
.with_n(Point2::new(2, 3), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
|
||||
.with_t(Point2::new(0, 4), "}")
|
||||
.with_t(Point2::new(0, 4), "} ")
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( Vec3i )").unwrap() {
|
||||
|
@ -163,6 +171,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
}
|
||||
}),
|
||||
SeqDecorStyle::VerticalSexpr,
|
||||
'\n',
|
||||
depth
|
||||
)
|
||||
)) 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,
|
||||
'\n',
|
||||
depth
|
||||
)
|
||||
)) 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()))
|
||||
},
|
||||
SeqDecorStyle::DoubleQuote,
|
||||
' ',
|
||||
depth
|
||||
)
|
||||
))
|
||||
|
|
|
@ -147,7 +147,7 @@ impl ProductEditor {
|
|||
} else {
|
||||
let mut b = VecBuffer::new();
|
||||
b.push(crate::diagnostics::make_todo(crate::terminal::make_label(&format!("complete {}", self.ctx.read().unwrap().type_term_to_str(&t[0])))));
|
||||
|
||||
|
||||
self.msg_buf.update(idx as usize, Some(b.get_port().to_sequence()));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
ctx: Arc<RwLock<Context>>,
|
||||
cmds: HashMap<String, Arc<dyn Action + Send + Sync>>,
|
||||
|
@ -119,6 +134,7 @@ impl Commander {
|
|||
Arc::new(RwLock::new(CharEditor::new()))
|
||||
},
|
||||
SeqDecorStyle::Plain,
|
||||
'\n',
|
||||
0
|
||||
);
|
||||
|
||||
|
@ -144,6 +160,7 @@ impl Commander {
|
|||
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("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 mut c = Commander {
|
||||
|
|
|
@ -80,6 +80,7 @@ async fn main() {
|
|||
)}),
|
||||
*/
|
||||
SeqDecorStyle::VerticalSexpr,
|
||||
'\n',
|
||||
0
|
||||
);
|
||||
|
||||
|
@ -153,6 +154,8 @@ async fn main() {
|
|||
for x in entry.addr.iter() {
|
||||
b.push(
|
||||
make_label(&format!("{}", x))
|
||||
.map_item(|p,a| a
|
||||
.add_style_back(TerminalStyle::fg_color((0, 100, 20))))
|
||||
);
|
||||
b.push(
|
||||
make_label(".")
|
||||
|
@ -206,7 +209,7 @@ async fn main() {
|
|||
if cur.tree_addr.len() > 0 {
|
||||
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 c in format!("{}", x).chars() {
|
||||
|
@ -215,13 +218,13 @@ async fn main() {
|
|||
}
|
||||
status_chars.push(TerminalAtom::new(
|
||||
'.',
|
||||
TerminalStyle::fg_color((120, 80, 80)),
|
||||
TerminalStyle::fg_color((150, 80,230))
|
||||
));
|
||||
}
|
||||
|
||||
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 {
|
||||
ListCursorMode::Insert => "INSERT",
|
||||
|
@ -236,7 +239,7 @@ async fn main() {
|
|||
}
|
||||
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 {
|
||||
for c in "Press <DN> to enter".chars() {
|
||||
|
|
|
@ -106,11 +106,13 @@ impl ProcessLauncher {
|
|||
editor: PTYListEditor::new(
|
||||
Box::new(|| Arc::new(RwLock::new(CharEditor::new()))),
|
||||
SeqDecorStyle::Plain,
|
||||
'\n',
|
||||
1
|
||||
),
|
||||
}))
|
||||
}) as Box<dyn Fn() -> Arc<RwLock<ProcessArg>> + Send + Sync>,
|
||||
SeqDecorStyle::HorizontalSexpr,
|
||||
' ',
|
||||
0
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue