aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-07-04 20:10:26 -0700
committerJames Campos <james.r.campos@gmail.com>2020-07-04 20:10:26 -0700
commitf54dfbd9ffdf1367bf027dc062bab82483def2ab (patch)
tree0ec70e9c125967de8e155751c07c09cc16cbbdb3 /src/main.rs
parentb3da35257f4cbb5ae3f80784ea12ca40c1721570 (diff)
downloadbk-f54dfbd9ffdf1367bf027dc062bab82483def2ab.tar.gz
show progress with metadata
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index bb7f508..9fb3b9a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -109,7 +109,20 @@ impl View for Metadata {
bk.view = Some(&Page);
}
fn render(&self, bk: &Bk) -> Vec<String> {
- bk.meta.clone()
+ let lines: Vec<usize> = bk.chapters.iter().map(|c| c.lines.len()).collect();
+ let current = lines[..bk.chapter].iter().sum::<usize>() + bk.line;
+ let total = lines.iter().sum::<usize>();
+ let progress = current as f32 / total as f32 * 100.0;
+
+ let pages = lines[bk.chapter] / bk.rows;
+ let page = bk.line / bk.rows;
+
+ let mut vec = vec![format!("chapter: {}/{}", page, pages),
+ format!("total: {:.0}%", progress),
+ String::new()
+ ];
+ vec.extend_from_slice(&bk.meta);
+ vec
}
}
@@ -124,7 +137,7 @@ impl View for Help {
Esc q Quit
Fn Help
Tab Table of Contents
- i Metadata
+ i Progress and Metadata
PageDown Right Space f l Page Down
PageUp Left b h Page Up