aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-04-27 15:32:58 -0700
committerJames Campos <james.r.campos@gmail.com>2020-04-27 15:32:58 -0700
commitc29013c6593b72a27d683e0c7b01b634a3a229fa (patch)
tree78b1642f70f35d26711411a42e93c79c0f9371df /src/main.rs
parent00b2ed05c03e6ccc1a76440d9849adb3696753d9 (diff)
downloadbk-c29013c6593b72a27d683e0c7b01b634a3a229fa.tar.gz
toc keys, rustfmt
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs
index 47b2a85..31c92e7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -107,17 +107,17 @@ impl Epub {
.map(|n| {
(
n.descendants()
- .find(|n| n.has_tag_name("content"))
- .unwrap()
- .attribute("src")
- .unwrap()
- .to_string(),
+ .find(|n| n.has_tag_name("content"))
+ .unwrap()
+ .attribute("src")
+ .unwrap()
+ .to_string(),
n.descendants()
- .find(|n| n.has_tag_name("text"))
- .unwrap()
- .text()
- .unwrap()
- .to_string()
+ .find(|n| n.has_tag_name("text"))
+ .unwrap()
+ .text()
+ .unwrap()
+ .to_string(),
)
})
.collect()
@@ -132,7 +132,8 @@ impl Epub {
.filter(|n| n.has_tag_name("a"))
.map(|n| {
let path = n.attribute("href").unwrap().to_string();
- let text = n.descendants()
+ let text = n
+ .descendants()
.filter(|n| n.is_text())
.map(|n| n.text().unwrap())
.collect();
@@ -146,18 +147,22 @@ impl Epub {
// playOrder is not a thing
let mut toc_idx = 0;
- paths.into_iter().enumerate().map(|(i, path)| {
- let zip_path = dirname.join(path).to_str().unwrap().to_string();
- let name = match toc.get(toc_idx) {
- Some(point) if point.0 == path => {
- toc_idx += 1;
- point.1.to_string()
- },
- _ => i.to_string(),
- };
- (name, zip_path)
- })
- .collect()
+ paths
+ .into_iter()
+ .enumerate()
+ .map(|(i, path)| {
+ let zip_path =
+ dirname.join(path).to_str().unwrap().to_string();
+ let name = match toc.get(toc_idx) {
+ Some(point) if point.0 == path => {
+ toc_idx += 1;
+ point.1.to_string()
+ }
+ _ => i.to_string(),
+ };
+ (name, zip_path)
+ })
+ .collect()
}
}
@@ -289,7 +294,9 @@ impl Bk {
fn run_nav(&mut self, e: Event) {
match e {
Event::Key(e) => match e.code {
- KeyCode::Tab | KeyCode::Char('q') => self.mode = Mode::Read,
+ KeyCode::Esc | KeyCode::Tab | KeyCode::Char('q') => {
+ self.mode = Mode::Read
+ }
KeyCode::Down | KeyCode::Char('j') => {
if self.nav_idx < self.toc.len() - 1 {
self.nav_idx += 1;
@@ -304,8 +311,10 @@ impl Bk {
self.get_chapter(self.nav_idx);
self.mode = Mode::Read;
}
- KeyCode::Char('g') => self.nav_idx = 0,
- KeyCode::Char('G') => self.nav_idx = self.toc.len() - 1,
+ KeyCode::Home | KeyCode::Char('g') => self.nav_idx = 0,
+ KeyCode::End | KeyCode::Char('G') => {
+ self.nav_idx = self.toc.len() - 1
+ }
_ => (),
},
Event::Mouse(e) => match e {