diff options
author | Jan Hrastnik | 2020-10-19 17:39:35 +0000 |
---|---|---|
committer | Jan Hrastnik | 2020-10-19 17:39:35 +0000 |
commit | 06502e5a2e18eeb0e6c4828b6cda0d4ba81cdbab (patch) | |
tree | 9b5834d80f1f7173bed0eef030055700bbc83f61 /helix-view/src/prompt.rs | |
parent | ae8ff9623efdf2a4267358d87d779b313c695689 (diff) |
added prompt close
Diffstat (limited to 'helix-view/src/prompt.rs')
-rw-r--r-- | helix-view/src/prompt.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 729533c5..12f29942 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -6,20 +6,24 @@ pub struct Prompt { pub prompt: String, pub line: String, pub cursor: usize, - completion_fn: Box<dyn FnMut(&str) -> Option<Vec<&str>>>, + pub completion: Option<Vec<String>>, + pub should_close: bool, + completion_fn: Box<dyn FnMut(&str) -> Option<Vec<String>>>, callback_fn: Box<dyn FnMut(&mut Editor, &str)>, } impl Prompt { pub fn new( prompt: String, - completion_fn: impl FnMut(&str) -> Option<Vec<&str>> + 'static, + completion_fn: impl FnMut(&str) -> Option<Vec<String>> + 'static, callback_fn: impl FnMut(&mut Editor, &str) + 'static, ) -> Prompt { Prompt { prompt, line: String::new(), cursor: 0, + completion: None, + should_close: false, completion_fn: Box::new(completion_fn), callback_fn: Box::new(callback_fn), } @@ -65,7 +69,7 @@ impl Prompt { } => self.insert_char(c), KeyEvent { code: KeyCode::Esc, .. - } => unimplemented!("Exit prompt!"), + } => self.should_close = true, KeyEvent { code: KeyCode::Right, .. @@ -93,9 +97,8 @@ impl Prompt { KeyEvent { code: KeyCode::Tab, .. } => { - let _completion = (self.completion_fn)(&self.line); + self.completion = (self.completion_fn)(&self.line); } - _ => (), } } |