summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-11 09:25:09 +0000
committerBlaž Hrastnik2020-12-11 09:25:09 +0000
commitada3f92c5b96e4c66f5647c4ac2487f3903692b3 (patch)
tree55017ebf8ea14a947de1d2e8108416f8d1467b04 /helix-term/src/commands.rs
parent5103dc96173afaa1c0793db56f60ec1fef1e0fc3 (diff)
wip: Getting the new prompt to render in a new layer.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs57
1 files changed, 55 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index a791f243..04482ef7 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -9,17 +9,21 @@ use helix_core::{
use once_cell::sync::Lazy;
+use crate::compositor::Compositor;
use crate::prompt::Prompt;
use helix_view::{
document::Mode,
view::{View, PADDING},
+ Editor,
};
pub struct Context<'a, 'b> {
pub count: usize,
pub view: &'a mut View,
pub executor: &'a smol::Executor<'b>,
+
+ pub callback: Option<crate::compositor::Callback>,
}
/// A command is a function that takes the current state and a count, and does a side-effect on the
@@ -333,8 +337,57 @@ pub fn append_mode(cx: &mut Context) {
}
// TODO: I, A, o and O can share a lot of the primitives.
-pub fn command_mode(_cx: &mut Context) {
- unimplemented!()
+pub fn command_mode(cx: &mut Context) {
+ cx.callback = Some(Box::new(|compositor: &mut Compositor| {
+ let prompt = Prompt::new(
+ ":".to_owned(),
+ |_input: &str| {
+ // TODO: i need this duplicate list right now to avoid borrow checker issues
+ let command_list = vec![
+ String::from("q"),
+ String::from("aaa"),
+ String::from("bbb"),
+ String::from("ccc"),
+ String::from("ddd"),
+ String::from("eee"),
+ String::from("averylongcommandaverylongcommandaverylongcommandaverylongcommandaverylongcommand"),
+ String::from("q"),
+ String::from("aaa"),
+ String::from("bbb"),
+ String::from("ccc"),
+ String::from("ddd"),
+ String::from("eee"),
+ String::from("q"),
+ String::from("aaa"),
+ String::from("bbb"),
+ String::from("ccc"),
+ String::from("ddd"),
+ String::from("eee"),
+ String::from("q"),
+ String::from("aaa"),
+ String::from("bbb"),
+ String::from("ccc"),
+ String::from("ddd"),
+ String::from("eee"),
+ String::from("q"),
+ String::from("aaa"),
+ String::from("bbb"),
+ String::from("ccc"),
+ String::from("ddd"),
+ String::from("eee"),
+ ];
+ command_list
+ .into_iter()
+ .filter(|command| command.contains(_input))
+ .collect()
+ }, // completion
+ |editor: &mut Editor, input: &str| match input {
+ "q" => editor.should_close = true,
+ _ => (),
+ },
+ );
+ compositor.push(Box::new(prompt));
+ }));
}
// calculate line numbers for each selection range