fn process_keypress(&mut self) -> bool {
        let handle = &mut io::stdin();
        let kp = Self::editor_read_key(handle);
        match kp {
            // editor commands
            Keypress::Quit => {
                if self.dirty && self.quit_times > 0 {
                    let quits_left = self.quit_times;
                    let msg = format!("WARNING!!! File has unsaved changes. Press Ctrl-Q {} more \
                                       times to quit.",
                                      quits_left);
                    self.set_status_message(msg);
                    self.quit_times -= 1;
                    return true;
                }
                return false;
            }
            Keypress::Save => {
                match self.save() {
                    Ok(len) => self.set_status_message(format!("{} bytes written to disk", len)),
                    Err(e) => self.set_status_message(format!("Can't save! I/O error: {}", e)),
                };
            }
            Keypress::Find => self.find(),

            // movement
            Keypress::Ar(arrow) => self.move_cursor(arrow),
            Keypress::Page(dir) => {
                match dir {
                    Arrow::Up => self.position.cy = self.position.rowoff,
                    Arrow::Down => {
                        self.position.cy = min(self.position.rowoff + self.screenrows - 1,
                                               self.rows.len())
                    }
                    _ => panic!("illegal paging"),
                }
                for _ in 0..self.screenrows {
                    self.move_cursor(dir);
                }
            }
            Keypress::Home => self.position.cx = 0,
            Keypress::End => {
                if self.position.cy < self.rows.len() {
                    self.position.cx = self.rows[self.position.cy].len;
                }
            }

            // editing
            Keypress::Enter => self.insert_newline(),
            Keypress::Backspace | Keypress::CtrlH => self.delete_char(),
            Keypress::Del => {
                self.move_cursor(Arrow::Right);
                self.delete_char();
            }

            // do nothing with Esc when editing
            Keypress::Esc => (),
            Keypress::Chr(c) => self.insert_char(c),
        };
        self.quit_times = QUIT_TIMES;
        true
    }
/// Read a single `Keypress` from stdin and perform the appropriate action
///
/// # Return value
/// true if the keypress indicated the program should terminate
Read a single `Keypress` from stdin and perform the appropriate action
Read a single ` Keypress ` from stdin and perform the appropriate action
fn process_keypress(&mut self) -> bool {
        let handle = &mut io::stdin();
        let kp = Self::editor_read_key(handle);
        match kp {
            // editor commands
            Keypress::Quit => {
                if self.dirty && self.quit_times > 0 {
                    let quits_left = self.quit_times;
                    let msg = format!("WARNING!!! File has unsaved changes. Press Ctrl-Q {} more \
                                       times to quit.",
                                      quits_left);
                    self.set_status_message(msg);
                    self.quit_times -= 1;
                    return true;
                }
                return false;
            }
            Keypress::Save => {
                match self.save() {
                    Ok(len) => self.set_status_message(format!("{} bytes written to disk", len)),
                    Err(e) => self.set_status_message(format!("Can't save! I/O error: {}", e)),
                };
            }
            Keypress::Find => self.find(),
            // movement
            Keypress::Ar(arrow) => self.move_cursor(arrow),
            Keypress::Page(dir) => {
                match dir {
                    Arrow::Up => self.position.cy = self.position.rowoff,
                    Arrow::Down => {
                        self.position.cy = min(self.position.rowoff + self.screenrows - 1,
                                               self.rows.len())
                    }
                    _ => panic!("illegal paging"),
                }
                for _ in 0..self.screenrows {
                    self.move_cursor(dir);
                }
            }
            Keypress::Home => self.position.cx = 0,
            Keypress::End => {
                if self.position.cy < self.rows.len() {
                    self.position.cx = self.rows[self.position.cy].len;
                }
            }
            // editing
            Keypress::Enter => self.insert_newline(),
            Keypress::Backspace | Keypress::CtrlH => self.delete_char(),
            Keypress::Del => {
                self.move_cursor(Arrow::Right);
                self.delete_char();
            }
            // do nothing with Esc when editing
            Keypress::Esc => (),
            Keypress::Chr(c) => self.insert_char(c),
        };
        self.quit_times = QUIT_TIMES;
        true
    }
fn process_keypress ( & mut self ) -> bool { let handle = & mut io :: stdin ( ) ; let kp = Self :: editor_read_key ( handle ) ; match kp { // editor commands Keypress :: Quit => { if self . dirty && self . quit_times > 0 { let quits_left = self . quit_times ; let msg = format ! ( " \
 " quits_left ) ; self . set_status_message ( msg ) ; self . quit_times -= 1 ; return true ; } return false ; } Keypress :: Save => { match self . save ( ) { Ok ( len ) => self . set_status_message ( format ! ( " " len ) ) , Err ( e ) => self . set_status_message ( format ! ( " " e ) ) , } ; } Keypress :: Find => self . find ( ) , // movement Keypress :: Ar ( arrow ) => self . move_cursor ( arrow ) , Keypress :: Page ( dir ) => { match dir { Arrow :: Up => self . position . cy = self . position . rowoff , Arrow :: Down => { self . position . cy = min ( self . position . rowoff + self . screenrows - 1 , self . rows . len ( ) ) } _ => panic ! ( " " ) , } for _ in 0 .. self . screenrows { self . move_cursor ( dir ) ; } } Keypress :: Home => self . position . cx = 0 , Keypress :: End => { if self . position . cy < self . rows . len ( ) { self . position . cx = self . rows [ self . position . cy ] . len ; } } // editing Keypress :: Enter => self . insert_newline ( ) , Keypress :: Backspace | Keypress :: CtrlH => self . delete_char ( ) , Keypress :: Del => { self . move_cursor ( Arrow :: Right ) ; self . delete_char ( ) ; } // do nothing with Esc when editing Keypress :: Esc => ( ) , Keypress :: Chr ( c ) => self . insert_char ( c ) , } ; self . quit_times = QUIT_TIMES ; true }
Read a single `Keypress` from stdin and perform the appropriate action
Read a single ` Keypress ` from stdin and perform the appropriate action
&mut self
return value
true if the keypress indicated the program should terminate
true if the keypress indicated the program should terminate