diff options
author | James Campos <james.r.campos@gmail.com> | 2020-05-04 22:44:21 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2020-05-04 22:44:21 -0700 |
commit | 9a15a4b9ac9f7919dc011f98f833f1bee16fb0ed (patch) | |
tree | 3c4bbc23fffb91930875b6fe183c733be907eccd /src/main.rs | |
parent | 0c7e26c49103ddc6cb835c7faaf1923c66d724f2 (diff) | |
download | bk-9a15a4b9ac9f7919dc011f98f833f1bee16fb0ed.tar.gz |
internal
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs index dbfd284..c37926b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use std::fs::File; -use std::io::{stdout, Error, Read, Write}; +use std::io::{stdout, Read, Write}; use crossterm::{ cursor, @@ -17,7 +17,7 @@ struct Epub { } impl Epub { - fn new(path: &str) -> Result<Self, Error> { + fn new(path: &str) -> std::io::Result<Self> { let file = File::open(path)?; Ok(Epub { @@ -270,8 +270,13 @@ impl Bk { )?; terminal::enable_raw_mode()?; - self.render(); loop { + match self.mode { + Mode::Read => self.render_read(), + Mode::Help => self.render_help(), + Mode::Nav => self.render_nav(), + Mode::Search => self.render_search(), + } match event::read()? { Event::Key(e) => match self.mode { Mode::Read => { @@ -291,7 +296,6 @@ impl Bk { // TODO Event::Mouse(_) => (), } - self.render(); } queue!( @@ -300,7 +304,7 @@ impl Bk { cursor::Show, //event::DisableMouseCapture )?; - stdout.flush()?; + //stdout.flush()?; terminal::disable_raw_mode() } fn get_chapter(&mut self, idx: usize) { @@ -454,14 +458,6 @@ impl Bk { } false } - fn render(&self) { - match self.mode { - Mode::Read => self.render_read(), - Mode::Help => self.render_help(), - Mode::Nav => self.render_nav(), - Mode::Search => self.render_search(), - } - } fn render_search(&self) { let mut stdout = stdout(); queue!( @@ -480,7 +476,7 @@ impl Bk { } fn render_nav(&self) { let mut stdout = stdout(); - queue!(stdout, terminal::Clear(ClearType::All),).unwrap(); + queue!(stdout, terminal::Clear(ClearType::All)).unwrap(); let end = std::cmp::min(self.nav_top + self.rows, self.toc.len()); for (i, line) in self.toc[self.nav_top..end].iter().enumerate() { @@ -496,7 +492,6 @@ impl Bk { }; queue!(stdout, cursor::MoveTo(0, i as u16), Print(s)).unwrap(); } - stdout.flush().unwrap(); } fn render_help(&self) { @@ -520,7 +515,7 @@ PageDown Right Space f l Page Down "#; let mut stdout = stdout(); - queue!(stdout, terminal::Clear(ClearType::All),).unwrap(); + queue!(stdout, terminal::Clear(ClearType::All)).unwrap(); for (i, line) in text.lines().enumerate() { queue!(stdout, cursor::MoveTo(0, i as u16), Print(line)).unwrap(); } @@ -581,6 +576,7 @@ fn main() { }); let mut bk = Bk::new(epub, &pos, 3); + // crossterm really shouldn't error bk.run().unwrap(); std::fs::write( |