fn prompt<F>(&mut self, prompt: &str, callback: &mut F) -> io::Result<String>
        where F: FnMut(&mut Editor, &str, Keypress)
    {
        let handle = &mut io::stdin();
        let mut input = String::with_capacity(128);
        loop {
            self.set_status_message(prompt.replace("{}", &input));
            self.refresh_screen()?;

            let keypress = Self::editor_read_key(handle);
            match keypress {
                Keypress::Backspace | Keypress::Del | Keypress::CtrlH => {
                    let input_len = input.len();
                    if input_len > 0 {
                        input.remove(input_len - 1);
                    }
                }
                Keypress::Enter => {
                    if !input.is_empty() {
                        self.set_status_message("".to_string());
                        callback(self, &input, keypress);
                        return Ok(input);
                    }
                }
                Keypress::Esc => {
                    self.set_status_message("".to_string());
                    callback(self, &input, keypress);
                    return Ok(String::new());
                }
                Keypress::Chr(c) => {
                    input.push(c);
                }
                _ => (),
            }
            callback(self, &input, keypress);
        }
    }
/// Display the prompt to the user and trigger the `callback` on every keypress
///
/// Switches focus to the status bar. A Enter or Esc keypress ends the prompt interaction.
///
/// * prompt string to display in the status bar, must contain one `{}` where the user's input
///          will appear as they type
/// * callback the callback to be triggered on each keypress. The callback will be passed the
///            last `Keypress`, the user input so far, and a mutable editor reference since
///            this method has mutable ownership of the Editor and a callback may need to
///            modify it.
///
/// # Return value
/// The state of the user's input when Enter was pressed, or empty string if the prompt was
/// cancelled via Esc
Display the prompt to the user and trigger the `callback` on every keypress
Switches focus to the status bar. A Enter or Esc keypress ends the prompt interaction.

prompt string to display in the status bar, must contain one `{}` where the user's input
will appear as they type
callback the callback to be triggered on each keypress. The callback will be passed the
last `Keypress`, the user input so far, and a mutable editor reference since
this method has mutable ownership of the Editor and a callback may need to
modify it.
Display the prompt to the user and trigger the ` callback ` on every keypress Switches focus to the status bar . A Enter or Esc keypress ends the prompt interaction . prompt string to display in the status bar must contain one ` {} ` where the user ' s input will appear as they type callback the callback to be triggered on each keypress . The callback will be passed the last ` Keypress ` the user input so far and a mutable editor reference since this method has mutable ownership of the Editor and a callback may need to modify it .
fn prompt<F>(&mut self, prompt: &str, callback: &mut F) -> io::Result<String>
        where F: FnMut(&mut Editor, &str, Keypress)
    {
        let handle = &mut io::stdin();
        let mut input = String::with_capacity(128);
        loop {
            self.set_status_message(prompt.replace("{}", &input));
            self.refresh_screen()?;
            let keypress = Self::editor_read_key(handle);
            match keypress {
                Keypress::Backspace | Keypress::Del | Keypress::CtrlH => {
                    let input_len = input.len();
                    if input_len > 0 {
                        input.remove(input_len - 1);
                    }
                }
                Keypress::Enter => {
                    if !input.is_empty() {
                        self.set_status_message("".to_string());
                        callback(self, &input, keypress);
                        return Ok(input);
                    }
                }
                Keypress::Esc => {
                    self.set_status_message("".to_string());
                    callback(self, &input, keypress);
                    return Ok(String::new());
                }
                Keypress::Chr(c) => {
                    input.push(c);
                }
                _ => (),
            }
            callback(self, &input, keypress);
        }
    }
fn prompt < F > ( & mut self , prompt : & str , callback : & mut F ) -> io :: Result < String > where F : FnMut ( & mut Editor , & str , Keypress ) { let handle = & mut io :: stdin ( ) ; let mut input = String :: with_capacity ( 128 ) ; loop { self . set_status_message ( prompt . replace ( " " , & input ) ) ; self . refresh_screen ( ) ? ; let keypress = Self :: editor_read_key ( handle ) ; match keypress { Keypress :: Backspace | Keypress :: Del | Keypress :: CtrlH => { let input_len = input . len ( ) ; if input_len > 0 { input . remove ( input_len - 1 ) ; } } Keypress :: Enter => { if ! input . is_empty ( ) { self . set_status_message ( " " . to_string ( ) ) ; callback ( self , & input , keypress ) ; return Ok ( input ) ; } } Keypress :: Esc => { self . set_status_message ( " " . to_string ( ) ) ; callback ( self , & input , keypress ) ; return Ok ( String :: new ( ) ) ; } Keypress :: Chr ( c ) => { input . push ( c ) ; } _ => ( ) , } callback ( self , & input , keypress ) ; } }
Display the prompt to the user and trigger the `callback` on every keypress
Switches focus to the status bar.
Display the prompt to the user and trigger the ` callback ` on every keypress Switches focus to the status bar .
&mut self
prompt
&str
callback
&mut F
return value
The state of the user's input when Enter was pressed, or empty string if the prompt was
cancelled via Esc
The state of the user ' s input when Enter was pressed or empty string if the prompt was cancelled via Esc