aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-06-20 23:44:32 -0700
committerJames Campos <james.r.campos@gmail.com>2020-06-20 23:44:32 -0700
commitdec535da812928d6dc0036e7f4760af17774dcbf (patch)
treec539d22421b097866d65365d11c0d4b25b296829 /src
parent1f5e2fb51c313c7534217735d21becef745928aa (diff)
downloadbk-dec535da812928d6dc0036e7f4760af17774dcbf.tar.gz
misc
Diffstat (limited to 'src')
-rw-r--r--src/epub.rs2
-rw-r--r--src/main.rs24
2 files changed, 17 insertions, 9 deletions
diff --git a/src/epub.rs b/src/epub.rs
index d74bd2a..491398b 100644
--- a/src/epub.rs
+++ b/src/epub.rs
@@ -98,7 +98,7 @@ impl Epub {
let doc = Document::parse(&xml).unwrap();
// zip expects unix path even on windows
let rootdir = match path.rfind('/') {
- Some(n) => &path[..n + 1],
+ Some(n) => &path[..=n],
None => "",
};
diff --git a/src/main.rs b/src/main.rs
index dffbfff..789ed46 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -80,9 +80,8 @@ trait View {
struct Mark;
impl View for Mark {
fn run(&self, bk: &mut Bk, kc: KeyCode) {
- match kc {
- KeyCode::Char(c) => bk.mark(c),
- _ => (),
+ if let KeyCode::Char(c) = kc {
+ bk.mark(c)
}
bk.view = Some(&Page)
}
@@ -94,9 +93,8 @@ impl View for Mark {
struct Jump;
impl View for Jump {
fn run(&self, bk: &mut Bk, kc: KeyCode) {
- match kc {
- KeyCode::Char(c) => bk.jump(c),
- _ => (),
+ if let KeyCode::Char(c) = kc {
+ bk.jump(c)
}
bk.view = Some(&Page);
}
@@ -377,7 +375,13 @@ impl Bk<'_> {
}
Bk {
- line: min(args.line, chapters[args.chapter].lines.len().saturating_sub(rows as usize)),
+ line: min(
+ args.line,
+ chapters[args.chapter]
+ .lines
+ .len()
+ .saturating_sub(rows as usize),
+ ),
chapters,
chapter: args.chapter,
mark: HashMap::new(),
@@ -530,7 +534,11 @@ struct Props {
fn restore(save_path: &str) -> Option<(String, Props)> {
let args: Args = argh::from_env();
let width = args.width;
- let path = args.path.map(|s| fs::canonicalize(s).unwrap().to_str().unwrap().to_string());
+ // XXX we shouldn't panic, but it gives a useful error, and we
+ // don't want to load the saved path if an invalid path is given
+ let path = args
+ .path
+ .map(|s| fs::canonicalize(s).unwrap().to_str().unwrap().to_string());
let save = fs::read_to_string(save_path).and_then(|s| {
let mut lines = s.lines();
Ok((