diff options
author | James Campos <james.r.campos@gmail.com> | 2021-07-31 04:15:54 -0700 |
---|---|---|
committer | James Campos <james.r.campos@gmail.com> | 2021-07-31 04:15:54 -0700 |
commit | 95c4c859e920e075616fc49d877f6d70cd56d70f (patch) | |
tree | a789168b44cc2c6b599a88acf98e34b0544b066d /src/view.rs | |
parent | 8f362702675e56cfcf38c78e78516dd64f91f3c8 (diff) | |
download | bk-95c4c859e920e075616fc49d877f6d70cd56d70f.tar.gz |
internal
Diffstat (limited to 'src/view.rs')
-rw-r--r-- | src/view.rs | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/view.rs b/src/view.rs index 5e48772..8194132 100644 --- a/src/view.rs +++ b/src/view.rs @@ -3,7 +3,7 @@ use crossterm::{ KeyCode::{self, *}, MouseEvent, MouseEventKind, }, - style::Attribute, + style::Attribute::*, }; use std::cmp::{min, Ordering}; use unicode_width::UnicodeWidthChar; @@ -142,7 +142,7 @@ impl View for Toc { } fn on_key(&self, bk: &mut Bk, kc: KeyCode) { match kc { - Esc | Tab | Left | Char('h') | Char('q') => { + Esc | Tab | Left | Char('h' | 'q') => { bk.jump_reset(); bk.cursor = 0; bk.view = &Page; @@ -171,12 +171,7 @@ impl View for Toc { .iter() .map(|c| c.title.clone()) .collect::<Vec<String>>(); - arr[bk.cursor] = format!( - "{}{}{}", - Attribute::Reverse, - arr[bk.cursor], - Attribute::NoReverse - ); + arr[bk.cursor] = format!("{}{}{}", Reverse, arr[bk.cursor], NoReverse); arr } } @@ -306,11 +301,11 @@ impl View for Page { Char('d') => self.scroll_down(bk, bk.rows / 2), Char('u') => self.scroll_up(bk, bk.rows / 2), Up | Char('k') => self.scroll_up(bk, 3), - Left | PageUp | Char('b') | Char('h') => { + Left | PageUp | Char('b' | 'h') => { self.scroll_up(bk, bk.rows); } Down | Char('j') => self.scroll_down(bk, 3), - Right | PageDown | Char('f') | Char('l') | Char(' ') => self.scroll_down(bk, bk.rows), + Right | PageDown | Char('f' | 'l' | ' ') => self.scroll_down(bk, bk.rows), Char('[') => self.prev_chapter(bk), Char(']') => self.next_chapter(bk), _ => (), @@ -330,8 +325,8 @@ impl View for Page { if !bk.query.is_empty() { let len = bk.query.len(); for (pos, _) in c.text[text_start..text_end].match_indices(&bk.query) { - search.push((text_start + pos, Attribute::Reverse)); - search.push((text_start + pos + len, Attribute::NoReverse)); + search.push((text_start + pos, Reverse)); + search.push((text_start + pos + len, NoReverse)); } } let mut search = search.into_iter().peekable(); @@ -344,8 +339,7 @@ impl View for Page { let map = c.attrs[start].2; let mut head = Vec::new(); - let list = [Attribute::Bold, Attribute::Italic, Attribute::Underlined]; - for attr in std::array::IntoIter::new(list) { + for attr in [Bold, Italic, Underlined] { if map.has(attr) { head.push((text_start, attr)); } |