@@ -24,7 +24,7 @@ pub struct Prompt {
24 selection: Option<usize>,
24 selection: Option<usize>,
25 history_register: Option<char>,
25 history_register: Option<char>,
26 history_pos: Option<usize>,
26 history_pos: Option<usize>,
27− completion_fn: Box<dyn FnMut(&str) -> Vec<Completion>>,
27+ completion_fn: Box<dyn FnMut(&Context, &str) -> Vec<Completion>>,
28 callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
28 callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
29 pub doc_fn: Box<dyn Fn(&str) -> Option<&'static str>>,
29 pub doc_fn: Box<dyn Fn(&str) -> Option<&'static str>>,
@@ -59,14 +59,14 @@ impl Prompt {
59 pub fn new(
59 pub fn new(
60 prompt: Cow<'static, str>,
60 prompt: Cow<'static, str>,
61 history_register: Option<char>,
61 history_register: Option<char>,
62− mut completion_fn: impl FnMut(&str) -> Vec<Completion> + 'static,
62+ completion_fn: impl FnMut(&Context, &str) -> Vec<Completion> + 'static,
63 callback_fn: impl FnMut(&mut Context, &str, PromptEvent) + 'static,
63 callback_fn: impl FnMut(&mut Context, &str, PromptEvent) + 'static,
64 ) -> Self {
64 ) -> Self {
67 line: String::new(),
67 line: String::new(),
68 cursor: 0,
68 cursor: 0,
69− completion: completion_fn(""),
69+ completion: Vec::new(),
70 selection: None,
70 selection: None,
71 history_register,
71 history_register,
72 history_pos: None,
72 history_pos: None,
@@ -177,13 +177,13 @@ impl Prompt {
180− pub fn insert_char(&mut self, c: char) {
180+ pub fn insert_char(&mut self, c: char, cx: &Context) {
181 self.line.insert(self.cursor, c);
181 self.line.insert(self.cursor, c);
182 let mut cursor = GraphemeCursor::new(self.cursor, self.line.len(), false);
182 let mut cursor = GraphemeCursor::new(self.cursor, self.line.len(), false);
183 if let Ok(Some(pos)) = cursor.next_boundary(&self.line, 0) {
183 if let Ok(Some(pos)) = cursor.next_boundary(&self.line, 0) {
184 self.cursor = pos;
184 self.cursor = pos;
186− self.completion = (self.completion_fn)(&self.line);
186+ self.completion = (self.completion_fn)(cx, &self.line);
187 self.exit_selection();
187 self.exit_selection();
@@ -205,61 +205,61 @@ impl Prompt {
205 self.cursor = self.line.len();
205 self.cursor = self.line.len();
208− pub fn delete_char_backwards(&mut self) {
208+ pub fn delete_char_backwards(&mut self, cx: &Context) {
209 let pos = self.eval_movement(Movement::BackwardChar(1));
209 let pos = self.eval_movement(Movement::BackwardChar(1));
210 self.line.replace_range(pos..self.cursor, "");
210 self.line.replace_range(pos..self.cursor, "");
211 self.cursor = pos;
211 self.cursor = pos;
213 self.exit_selection();
213 self.exit_selection();
214− self.completion = (self.completion_fn)(&self.line);
214+ self.completion = (self.completion_fn)(cx, &self.line);
217− pub fn delete_char_forwards(&mut self) {
217+ pub fn delete_char_forwards(&mut self, cx: &Context) {
218 let pos = self.eval_movement(Movement::ForwardChar(1));
218 let pos = self.eval_movement(Movement::ForwardChar(1));
219 self.line.replace_range(self.cursor..pos, "");
219 self.line.replace_range(self.cursor..pos, "");
221 self.exit_selection();
221 self.exit_selection();
222− self.completion = (self.completion_fn)(&self.line);
222+ self.completion = (self.completion_fn)(cx, &self.line);
225− pub fn delete_word_backwards(&mut self) {
225+ pub fn delete_word_backwards(&mut self, cx: &Context) {
226 let pos = self.eval_movement(Movement::BackwardWord(1));
226 let pos = self.eval_movement(Movement::BackwardWord(1));
227 self.line.replace_range(pos..self.cursor, "");
227 self.line.replace_range(pos..self.cursor, "");
228 self.cursor = pos;
228 self.cursor = pos;
230 self.exit_selection();
230 self.exit_selection();
231− self.completion = (self.completion_fn)(&self.line);
231+ self.completion = (self.completion_fn)(cx, &self.line);
234− pub fn delete_word_forwards(&mut self) {
234+ pub fn delete_word_forwards(&mut self, cx: &Context) {
235 let pos = self.eval_movement(Movement::ForwardWord(1));
235 let pos = self.eval_movement(Movement::ForwardWord(1));
236 self.line.replace_range(self.cursor..pos, "");
236 self.line.replace_range(self.cursor..pos, "");
238 self.exit_selection();
238 self.exit_selection();
239− self.completion = (self.completion_fn)(&self.line);
239+ self.completion = (self.completion_fn)(cx, &self.line);
242− pub fn kill_to_start_of_line(&mut self) {
242+ pub fn kill_to_start_of_line(&mut self, cx: &Context) {
243 let pos = self.eval_movement(Movement::StartOfLine);
243 let pos = self.eval_movement(Movement::StartOfLine);
244 self.line.replace_range(pos..self.cursor, "");
244 self.line.replace_range(pos..self.cursor, "");
245 self.cursor = pos;
245 self.cursor = pos;
247 self.exit_selection();
247 self.exit_selection();
248− self.completion = (self.completion_fn)(&self.line);
248+ self.completion = (self.completion_fn)(cx, &self.line);
251− pub fn kill_to_end_of_line(&mut self) {
251+ pub fn kill_to_end_of_line(&mut self, cx: &Context) {
252 let pos = self.eval_movement(Movement::EndOfLine);
252 let pos = self.eval_movement(Movement::EndOfLine);
253 self.line.replace_range(self.cursor..pos, "");
253 self.line.replace_range(self.cursor..pos, "");
255 self.exit_selection();
255 self.exit_selection();
256− self.completion = (self.completion_fn)(&self.line);
256+ self.completion = (self.completion_fn)(cx, &self.line);
259− pub fn clear(&mut self) {
259+ pub fn clear(&mut self, cx: &Context) {
260 self.line.clear();
260 self.line.clear();
261 self.cursor = 0;
261 self.cursor = 0;
262− self.completion = (self.completion_fn)(&self.line);
262+ self.completion = (self.completion_fn)(cx, &self.line);
263 self.exit_selection();
263 self.exit_selection();
@@ -442,16 +442,16 @@ impl Component for Prompt {
442 ctrl!('f') | key!(Right) => self.move_cursor(Movement::ForwardChar(1)),
442 ctrl!('f') | key!(Right) => self.move_cursor(Movement::ForwardChar(1)),
443 ctrl!('e') | key!(End) => self.move_end(),
443 ctrl!('e') | key!(End) => self.move_end(),
444 ctrl!('a') | key!(Home) => self.move_start(),
444 ctrl!('a') | key!(Home) => self.move_start(),
445− ctrl!('w') => self.delete_word_backwards(),
445+ ctrl!('w') => self.delete_word_backwards(cx),
446− alt!('d') => self.delete_word_forwards(),
446+ alt!('d') => self.delete_word_forwards(cx),
447− ctrl!('k') => self.kill_to_end_of_line(),
447+ ctrl!('k') => self.kill_to_end_of_line(cx),
448− ctrl!('u') => self.kill_to_start_of_line(),
448+ ctrl!('u') => self.kill_to_start_of_line(cx),
449 ctrl!('h') | key!(Backspace) => {
449 ctrl!('h') | key!(Backspace) => {
450− self.delete_char_backwards();
450+ self.delete_char_backwards(cx);
451 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
451 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
453 ctrl!('d') | key!(Delete) => {
453 ctrl!('d') | key!(Delete) => {
454− self.delete_char_forwards();
454+ self.delete_char_forwards(cx);
455 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
455 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
457 ctrl!('s') => {
457 ctrl!('s') => {
@@ -474,7 +474,7 @@ impl Component for Prompt {
475 key!(Enter) => {
475 key!(Enter) => {
476 if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) {
476 if self.selection.is_some() && self.line.ends_with(std::path::MAIN_SEPARATOR) {
477− self.completion = (self.completion_fn)(&self.line);
477+ self.completion = (self.completion_fn)(cx, &self.line);
478 self.exit_selection();
478 self.exit_selection();
480 (self.callback_fn)(cx, &self.line, PromptEvent::Validate);
480 (self.callback_fn)(cx, &self.line, PromptEvent::Validate);
@@ -515,7 +515,7 @@ impl Component for Prompt {
515 code: KeyCode::Char(c),
515 code: KeyCode::Char(c),
516 modifiers,
516 modifiers,
517 } if !modifiers.contains(KeyModifiers::CONTROL) => {
517 } if !modifiers.contains(KeyModifiers::CONTROL) => {
518− self.insert_char(c);
518+ self.insert_char(c, cx);
519 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
519 (self.callback_fn)(cx, &self.line, PromptEvent::Update);
@@ -525,6 +525,7 @@ impl Component for Prompt {
527 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
527 fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
528+ self.completion = (self.completion_fn)(cx, &self.line);
528 self.render_prompt(area, surface, cx)
529 self.render_prompt(area, surface, cx)