aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-04-30 23:09:47 -0700
committerJames Campos <james.r.campos@gmail.com>2020-04-30 23:09:47 -0700
commit0c7e26c49103ddc6cb835c7faaf1923c66d724f2 (patch)
tree37bd1ea0a3424f55c380e33e0ac01d16089cccb2
parent77ae1bde466e20775352fe3c792750cc3b2ccee3 (diff)
downloadbk-0c7e26c49103ddc6cb835c7faaf1923c66d724f2.tar.gz
internal
-rw-r--r--README.md2
-rw-r--r--src/main.rs39
2 files changed, 21 insertions, 20 deletions
diff --git a/README.md b/README.md
index 45fc5c8..5c00a80 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
# bk
-bk is a WIP terminal epub reader
+bk is a WIP terminal epub reader. currently only tested on linux.
# install
diff --git a/src/main.rs b/src/main.rs
index fc8d305..dbfd284 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,13 +12,6 @@ use crossterm::{
use roxmltree::Document;
-enum Mode {
- Help,
- Nav,
- Read,
- Search,
-}
-
struct Epub {
container: zip::ZipArchive<File>,
}
@@ -38,7 +31,7 @@ impl Epub {
let last = acc.last_mut().unwrap();
last.push(text);
}
- return
+ return;
}
match n.tag_name().name() {
@@ -181,7 +174,7 @@ impl Epub {
.into_iter()
.enumerate()
.map(|(i, path)| {
- let title = toc.remove(path).unwrap_or(i.to_string());
+ let title = toc.remove(path).unwrap_or_else(|| i.to_string());
let path = rootdir.join(path).to_str().unwrap().to_string();
(title, path)
})
@@ -218,6 +211,20 @@ fn wrap(text: String, width: u16) -> Vec<String> {
wrapped
}
+struct Position(String, usize, usize);
+
+enum Direction {
+ Forward,
+ Backward,
+}
+
+enum Mode {
+ Help,
+ Nav,
+ Read,
+ Search,
+}
+
struct Bk {
mode: Mode,
epub: Epub,
@@ -233,16 +240,9 @@ struct Bk {
search: String,
}
-struct Position(String, usize, usize);
-enum Direction {
- Forward,
- Backward,
-}
-
impl Bk {
- fn new(pos: &Position, pad: u16) -> Result<Self, Error> {
+ fn new(mut epub: Epub, pos: &Position, pad: u16) -> Self {
let (cols, rows) = terminal::size().unwrap();
- let mut epub = Epub::new(&pos.0)?;
let mut bk = Bk {
mode: Mode::Read,
chapter: Vec::new(),
@@ -258,7 +258,7 @@ impl Bk {
search: String::new(),
};
bk.get_chapter(pos.1);
- Ok(bk)
+ bk
}
fn run(&mut self) -> crossterm::Result<()> {
let mut stdout = stdout();
@@ -575,11 +575,12 @@ fn main() {
std::process::exit(1);
});
- let mut bk = Bk::new(&pos, 3).unwrap_or_else(|e| {
+ let epub = Epub::new(&pos.0).unwrap_or_else(|e| {
println!("error reading epub: {}", e);
std::process::exit(1);
});
+ let mut bk = Bk::new(epub, &pos, 3);
bk.run().unwrap();
std::fs::write(