diff options
author | NerdyPepper <[email protected]> | 2018-06-28 08:29:26 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2018-06-28 08:29:26 +0100 |
commit | a5bf6b5555c42a47e4d8892748fe4452977396fd (patch) | |
tree | 4bf59abb48d74c3094a63df2007b75cc81a8dbd3 /src | |
parent | 2b8ba07df6f7cce933e5f16018860128001ce6b5 (diff) |
Move from global callbacks to events
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index ad62b77..9add0c0 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -3,9 +3,8 @@ extern crate serde_json; | |||
3 | extern crate cursive; | 3 | extern crate cursive; |
4 | 4 | ||
5 | use cursive::Cursive; | 5 | use cursive::Cursive; |
6 | use cursive::align::HAlign; | ||
7 | use cursive::traits::*; | 6 | use cursive::traits::*; |
8 | use cursive::views::{ TextView, Dialog, EditView, SelectView, LinearLayout, DummyView }; | 7 | use cursive::views::{ TextView, Dialog, EditView, SelectView, OnEventView }; |
9 | 8 | ||
10 | pub mod content; | 9 | pub mod content; |
11 | use content::*; | 10 | use content::*; |
@@ -16,11 +15,6 @@ fn main() { | |||
16 | 15 | ||
17 | main.add_global_callback('q', |s| s.quit()); | 16 | main.add_global_callback('q', |s| s.quit()); |
18 | main.add_global_callback('s', |s| search(s)); | 17 | main.add_global_callback('s', |s| search(s)); |
19 | main.add_global_callback('t', |s| match s.pop_layer() { | ||
20 | Some(_) => (), | ||
21 | None => s.add_layer( Dialog::text("Stack is empty!") | ||
22 | .title("Error") | ||
23 | )}); | ||
24 | 18 | ||
25 | main.run(); | 19 | main.run(); |
26 | } | 20 | } |
@@ -38,13 +32,14 @@ fn search(s: &mut Cursive){ | |||
38 | .with_all_str(result) | 32 | .with_all_str(result) |
39 | .on_submit(on_submit); | 33 | .on_submit(on_submit); |
40 | s.add_layer(Dialog::around(choose_result) | 34 | s.add_layer(Dialog::around(choose_result) |
41 | .title("Search Results")); | 35 | .title("Search Results") |
36 | .fixed_size(( 45,8 ))); | ||
42 | } | 37 | } |
43 | 38 | ||
44 | s.add_layer(Dialog::around(EditView::new() | 39 | s.add_layer(Dialog::around(EditView::new() |
45 | .on_submit(go) | 40 | .on_submit(go) |
46 | .with_id("search") | 41 | .with_id("search") |
47 | .fixed_size(( 15,2 ))) | 42 | ) |
48 | .title("Search for a page") | 43 | .title("Search for a page") |
49 | .button("Go", |s| { | 44 | .button("Go", |s| { |
50 | let search_txt = s.call_on_id( "search", |v: &mut EditView| { | 45 | let search_txt = s.call_on_id( "search", |v: &mut EditView| { |
@@ -72,10 +67,13 @@ fn on_submit(s: &mut Cursive, name: &String) { | |||
72 | }; | 67 | }; |
73 | 68 | ||
74 | s.add_layer( | 69 | s.add_layer( |
75 | Dialog::around(TextView::new(extract)) | 70 | Dialog::around( |
71 | OnEventView::new(TextView::new(extract)) | ||
72 | .on_event('t', |s| match s.pop_layer() { _ => () }) | ||
73 | ) | ||
76 | .title(heading) | 74 | .title(heading) |
77 | .padding_right(5) | 75 | .padding_right(2) |
78 | .padding_left(5) | 76 | .padding_left(2) |
79 | .max_width(80) | 77 | .max_width(80) |
80 | ); | 78 | ); |
81 | } | 79 | } |