diff options
author | James Campos <james.r.campos@gmail.com> | 2020-04-21 01:17:20 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2020-04-21 01:17:20 -0700 |
commit | dd520811d2a05492f7ab7b2211ca7945e1f8e10a (patch) | |
tree | c7ebca8c22b02c1aa562ad4e517d61a9d73b66a7 | |
parent | d76529a0dc6237510fa3329678326052f73f2d47 (diff) | |
download | bk-dd520811d2a05492f7ab7b2211ca7945e1f8e10a.tar.gz |
overflow
-rw-r--r-- | src/main.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 267f171..e232c40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,15 +124,14 @@ impl Bk { ) -> Result<Self, Error> { let (cols, rows) = terminal::size().unwrap(); let mut epub = Epub::new(path)?; - let toc = epub.get_toc(); let mut bk = Bk { chapter: Vec::new(), chapter_idx, + toc: epub.get_toc(), epub, pos, pad, cols, - toc, rows: rows as usize, }; bk.get_chapter(chapter_idx); @@ -203,7 +202,11 @@ impl Bk { | KeyCode::PageUp | KeyCode::Char('h') => { if self.pos > 0 { - self.pos -= self.rows; + if self.pos < self.rows { + self.pos = 0; + } else { + self.pos -= self.rows; + } } else if self.chapter_idx > 0 { self.get_chapter(self.chapter_idx - 1); self.pos = (self.chapter.len() / self.rows) * self.rows; |