aboutsummaryrefslogtreecommitdiffstats
path: root/src/view.rs
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2021-01-25 17:51:14 -0800
committerJames Campos <james.r.campos@gmail.com>2021-01-25 17:51:14 -0800
commit5c46d948c54cbeb0a5c3403df6f4bd0236a59757 (patch)
treee45a11901b82e642ae6bab2d2f9649935d0a2935 /src/view.rs
parenta7f3196c240c790e281e7a24ed2d6d2fa2da0776 (diff)
downloadbk-5c46d948c54cbeb0a5c3403df6f4bd0236a59757.tar.gz
ignore mousemove, fix #16
Diffstat (limited to 'src/view.rs')
-rw-r--r--src/view.rs33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/view.rs b/src/view.rs
index 1fdb449..6d4af33 100644
--- a/src/view.rs
+++ b/src/view.rs
@@ -1,8 +1,7 @@
use crossterm::{
event::{
KeyCode::{self, *},
- MouseEvent,
- MouseEventKind,
+ MouseEvent, MouseEventKind,
},
style::Attribute,
};
@@ -25,7 +24,7 @@ impl View for Mark {
if let Char(c) = kc {
bk.mark(c)
}
- bk.view = Some(&Page)
+ bk.view = &Page
}
fn render(&self, bk: &Bk) -> Vec<String> {
Page::render(&Page, bk)
@@ -40,7 +39,7 @@ impl View for Jump {
bk.jump(pos);
}
}
- bk.view = Some(&Page);
+ bk.view = &Page;
}
fn render(&self, bk: &Bk) -> Vec<String> {
Page::render(&Page, bk)
@@ -50,7 +49,7 @@ impl View for Jump {
struct Metadata;
impl View for Metadata {
fn on_key(&self, bk: &mut Bk, _: KeyCode) {
- bk.view = Some(&Page);
+ bk.view = &Page;
}
fn render(&self, bk: &Bk) -> Vec<String> {
let lines: Vec<usize> = bk.chapters.iter().map(|c| c.lines.len()).collect();
@@ -75,7 +74,7 @@ impl View for Metadata {
struct Help;
impl View for Help {
fn on_key(&self, bk: &mut Bk, _: KeyCode) {
- bk.view = Some(&Page);
+ bk.view = &Page;
}
fn render(&self, _: &Bk) -> Vec<String> {
let text = r#"
@@ -125,7 +124,7 @@ impl Toc {
if start + row < bk.chapters.len() {
bk.chapter = start + row;
bk.line = 0;
- bk.view = Some(&Page);
+ bk.view = &Page;
}
}
}
@@ -146,12 +145,12 @@ impl View for Toc {
Esc | Tab | Left | Char('h') | Char('q') => {
bk.jump_reset();
bk.cursor = 0;
- bk.view = Some(&Page);
+ bk.view = &Page;
}
Enter | Right | Char('l') => {
bk.cursor = 0;
bk.line = 0;
- bk.view = Some(&Page);
+ bk.view = &Page;
}
Down | Char('j') => self.next(bk, 1),
Up | Char('k') => self.prev(bk, 1),
@@ -236,16 +235,16 @@ impl View for Page {
}
fn on_key(&self, bk: &mut Bk, kc: KeyCode) {
match kc {
- Esc | Char('q') => bk.view = None,
+ Esc | Char('q') => bk.quit = true,
Tab => {
bk.mark('\'');
Toc.cursor(bk);
- bk.view = Some(&Toc);
+ bk.view = &Toc;
}
- F(_) => bk.view = Some(&Help),
- Char('m') => bk.view = Some(&Mark),
- Char('\'') => bk.view = Some(&Jump),
- Char('i') => bk.view = Some(&Metadata),
+ F(_) => bk.view = &Help,
+ Char('m') => bk.view = &Mark,
+ Char('\'') => bk.view = &Jump,
+ Char('i') => bk.view = &Metadata,
Char('?') => bk.start_search(Direction::Prev),
Char('/') => bk.start_search(Direction::Next),
Char('N') => {
@@ -380,10 +379,10 @@ impl View for Search {
match kc {
Esc => {
bk.jump_reset();
- bk.view = Some(&Page);
+ bk.view = &Page;
}
Enter => {
- bk.view = Some(&Page);
+ bk.view = &Page;
}
Backspace => {
bk.query.pop();