From b878be7919a079b17768a25f274db786ddc42c99 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Tue, 19 Jun 2018 18:42:53 +0530 Subject: Begin working on search interface --- src/main.rs | 44 +++++++++++++++++++++++++++++++------------- 1 file 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 @@ extern crate reqwest; extern crate serde_json; +extern crate cursive; use serde_json::Value; +use cursive::Cursive; +use cursive::{TextView, Dialog, EditView, SelectView}; + pub mod content; fn main() { - 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); - let res = reqwest::get(&url); - - match res { - Ok(res) => { - if res.status().is_success() { - content::get_extract("") - } - } - - Err(_) { - panic!("Oh no!"); - } + // Initial setup + let mut main = Cursive::default(); + + main.add_layer(TextView::new("Welcome!"))); + main.add_global_callback('q', |s| s.quit()); + main.add_global_callback('s', search())); +} + +fn search(s: &mut Cursive){ + fn go(s: &mut Cursive, search: &str) { + s.pop_layer(); + let search_results: Vec = content::get_search_results(); + let sv = SelectView::with_all_strs(search_results.iter()); } + + s.add_layer(Dialog::around(EditView::new() + .on_submit(render_page()) + .with_id("search") + .fixed_width(10)) + .title("Search for a page") + .button("Go", |s| { + let search_txt = s.call_on_id( "search", |v: &mut EditView| { + v.get_content() + }).unwrap(); + + go(s, search_txt); + }) + .button("Cancel", |s| s.pop_layer())); } -- cgit v1.2.3