From f54dfbd9ffdf1367bf027dc062bab82483def2ab Mon Sep 17 00:00:00 2001 From: James Campos Date: Sat, 4 Jul 2020 20:10:26 -0700 Subject: show progress with metadata --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src') 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 { - bk.meta.clone() + let lines: Vec = bk.chapters.iter().map(|c| c.lines.len()).collect(); + let current = lines[..bk.chapter].iter().sum::() + bk.line; + let total = lines.iter().sum::(); + 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 -- cgit v1.2.3