diff options
author | James Campos <james.r.campos@gmail.com> | 2020-07-22 04:57:30 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2020-07-22 04:57:30 -0700 |
commit | 6b618c60009b421d6a5b26cdc15f51ef7cb43209 (patch) | |
tree | 288e8c03e412a41abc4a8ea8d857adb42872818f /src/main.rs | |
parent | 4cb47493b0f7362b06f87a3c49419087ee18ab54 (diff) | |
download | bk-6b618c60009b421d6a5b26cdc15f51ef7cb43209.tar.gz |
internal
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs index 90a60cd..141e353 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ fn wrap(text: &str, max_cols: usize) -> Vec<(usize, usize)> { lines } -fn get_line (lines: &Vec<(usize, usize)>, byte: usize) -> usize { +fn get_line(lines: &Vec<(usize, usize)>, byte: usize) -> usize { match lines.binary_search_by_key(&byte, |&(a, _)| a) { Ok(n) => n, Err(n) => n - 1, @@ -509,10 +509,9 @@ struct Bk<'a> { line: usize, mark: HashMap<char, (usize, usize)>, links: HashMap<String, (usize, usize)>, - // terminal + // layout cols: u16, rows: usize, - // user config max_width: u16, // view state view: Option<&'a dyn View>, @@ -544,32 +543,26 @@ impl Bk<'_> { } } - let line = get_line(&chapters[args.chapter].lines, args.byte); - - let mut mark = HashMap::new(); - let view: &dyn View = if args.toc { - // need an initial mark to reset to - mark.insert('\'', (args.chapter, line)); - &Nav - } else { - &Page - }; - - Bk { + let mut bk = Bk { chapters, chapter: args.chapter, - line, - mark, + line: 0, + mark: HashMap::new(), links: epub.links, cols, rows: rows as usize, max_width: args.width, - view: Some(view), + view: Some(if args.toc { &Nav } else { &Page }), dir: Direction::Next, meta, nav_top: 0, query: String::new(), - } + }; + + bk.line = get_line(&bk.chap().lines, args.byte); + bk.mark('\''); + + bk } fn pad(&self) -> u16 { self.cols.saturating_sub(self.max_width) / 2 |