aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2018-06-19 14:12:53 +0100
committerNerdyPepper <[email protected]>2018-06-19 14:12:53 +0100
commitb878be7919a079b17768a25f274db786ddc42c99 (patch)
tree1ada424e467a15454b4ef96f2652ae53a6506a5a
parent7e9e1d7850c95cc514c8cac54d8e6443d4c73742 (diff)
Begin working on search interface
-rw-r--r--src/main.rs44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 1573cdb..6ed1480 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,23 +1,41 @@
1extern crate reqwest; 1extern crate reqwest;
2extern crate serde_json; 2extern crate serde_json;
3extern crate cursive;
3 4
4use serde_json::Value; 5use serde_json::Value;
5 6
7use cursive::Cursive;
8use cursive::{TextView, Dialog, EditView, SelectView};
9
6pub mod content; 10pub mod content;
7 11
8fn main() { 12fn main() {
9 let url = format!("https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&list=&meta=&indexpageids=1&continue=%7C%7Cimageinfo&titles={}&exlimit=20&explaintext=1&exsectionformat=plain", title); 13 // Initial setup
10 let res = reqwest::get(&url); 14 let mut main = Cursive::default();
11 15
12 match res { 16 main.add_layer(TextView::new("Welcome!")));
13 Ok(res) => { 17 main.add_global_callback('q', |s| s.quit());
14 if res.status().is_success() { 18 main.add_global_callback('s', search()));
15 content::get_extract("") 19}
16 } 20
17 } 21fn search(s: &mut Cursive){
18 22 fn go(s: &mut Cursive, search: &str) {
19 Err(_) { 23 s.pop_layer();
20 panic!("Oh no!"); 24 let search_results: Vec<String> = content::get_search_results();
21 } 25 let sv = SelectView::with_all_strs(search_results.iter());
22 } 26 }
27
28 s.add_layer(Dialog::around(EditView::new()
29 .on_submit(render_page())
30 .with_id("search")
31 .fixed_width(10))
32 .title("Search for a page")
33 .button("Go", |s| {
34 let search_txt = s.call_on_id( "search", |v: &mut EditView| {
35 v.get_content()
36 }).unwrap();
37
38 go(s, search_txt);
39 })
40 .button("Cancel", |s| s.pop_layer()));
23} 41}