diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index b696fbe..9c30520 100644 --- a/src/main.rs +++ b/src/main.rs @@ -373,6 +373,77 @@ impl State { write!(stdout(), "\x1b[{}H", self.cursor_row + 1)?; stdout().flush()?; } + Key::Home => { + self.line_offset = 0; + self.cursor_col = 0; + write!(stdout(), "\x1b[{}H", self.cursor_row + 1)?; + stdout().flush()?; + } + Key::End => { + let size = term::size()?; + self.line_offset = line_offset(stdin, &self.line(), size.ws_col - 2)?; + self.update_cursor_col(stdin)?; + stdout().flush()?; + } + Key::PgUp => { + if self.row_start == 0 { + self.cursor_row = 0; + self.cursor_col = 0; + self.line_offset = 0; + write!(stdout(), "\x1b[H")?; + stdout().flush()?; + return Ok(true); + } + let size = term::size()?; + let mut start = 0; + if usize::from(size.ws_row) < self.row_start + 2 { + start = self.row_start + 2 - usize::from(size.ws_row); + }; + self.line_offset = line_offset( + stdin, + &self.buf.line(start + usize::from(self.cursor_row)), + self.cursor_col, + )?; + self.row_start = start; + self.repaint_screen()?; + self.update_cursor_col(stdin)?; + stdout().flush()?; + } + Key::PgDn => { + let size = term::size()?; + if self.buf.lines() - self.row_start < usize::from(size.ws_row) { + self.cursor_row = u16::try_from(self.buf.lines() - self.row_start) + .expect("self.buf.lines() - self.row_start < size.ws_row"); + self.line_offset = self.line().len(); + self.update_cursor_col(stdin)?; + stdout().flush()?; + return Ok(true); + } + let mut start = self.row_start + 1; + if size.ws_row >= 2 { + start = self.row_start + usize::from(size.ws_row) - 2; + } + if start + usize::from(self.cursor_row) <= self.buf.lines() { + self.line_offset = line_offset( + stdin, + &self.buf.line(start + usize::from(self.cursor_row)), + self.cursor_col, + )?; + self.row_start = start; + self.repaint_screen()?; + self.update_cursor_col(stdin)?; + stdout().flush()?; + return Ok(true); + } + self.line_offset = + line_offset(stdin, &self.buf.line(self.buf.lines()), self.cursor_col)?; + self.row_start = start; + self.cursor_row = u16::try_from(self.buf.lines() - start) + .expect("start + self.cursor_row > self.buf.lines()"); + self.repaint_screen()?; + self.update_cursor_col(stdin)?; + stdout().flush()?; + } Key::Byte(CTRL_Q) => { return Ok(false); } |
