blob: bc1188d22c2aab342ef381b7b0b68c3e9dec74bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
extern crate reqwest;
extern crate serde_json;
extern crate cursive;
use serde_json::Value;
use cursive::Cursive;
use cursive::traits::*;
use cursive::views::{TextView, Dialog, EditView, SelectView};
pub mod content;
fn main() {
// 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', |s| search(s));
main.run();
}
fn search(s: &mut Cursive){
fn go(s: &mut Cursive, search: &str) {
s.pop_layer();
let results = content::get_search_results(search);
s.add_layer(SelectView::new().with_all_str(results));
}
s.add_layer(Dialog::around(EditView::new()
.on_submit(go)
.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| match s.pop_layer(){
Some(_) => (),
None => (),
}));
}
|