From fa55b1e51c2310cf73689da37c5c57441d7e89c3 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Thu, 15 Oct 2020 12:08:01 +0200 Subject: added closures to prompt --- helix-view/src/prompt.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'helix-view/src') diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 3cb15f68..8cfb9fde 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -6,15 +6,21 @@ use std::string::String; pub struct Prompt { pub buffer: String, pub cursor_loc: usize, + completion_fn: Box Option>>, + callback_fn: Box, } impl Prompt { - pub fn new() -> Prompt { - let prompt = Prompt { + pub fn new( + completion_fn: impl FnMut(&str) -> Option> + 'static, + callback_fn: impl Fn(&str) + 'static, + ) -> Prompt { + Prompt { buffer: String::from(""), cursor_loc: 0, - }; - prompt + completion_fn: Box::new(completion_fn), + callback_fn: Box::new(callback_fn), + } } pub fn insert_char(&mut self, c: char) { @@ -49,10 +55,6 @@ impl Prompt { } } - pub fn success_fn() { - // TODO: - } - pub fn handle_input(&mut self, key_event: KeyEvent, view: &mut View) { match key_event { KeyEvent { @@ -82,6 +84,10 @@ impl Prompt { code: KeyCode::Backspace, .. } => self.delete_char_backwards(), + KeyEvent { + code: KeyCode::Enter, + .. + } => (self.callback_fn)(&self.buffer), _ => (), } } -- cgit v1.2.3-70-g09d2