Browse Source

Handle Input status

openbsd
Julien Blanchard 7 years ago
parent
commit
96ff8c2bde
  1. 10
      src/history.rs.rej
  2. 25
      src/main.rs

10
src/history.rs.rej

@ -0,0 +1,10 @@
diff a/src/history.rs b/src/history.rs (rejected hunks)
@@ -2,7 +2,7 @@ use url::Url;
use std::sync::Mutex;
lazy_static! {
- static ref HISTORY: Mutex<Vec<Url>> = Mutex::new(vec![]);
+ static ref HISTORY: Mutex<BTreeSet<Url>> = Mutex::new(vec![]);
}
pub fn init() {

25
src/main.rs

@ -9,7 +9,7 @@ use cursive::theme::Effect;
use cursive::traits::*;
use cursive::utils::markup::StyledString;
use cursive::view::Scrollable;
use cursive::views::{Dialog, EditView, Panel, SelectView};
use cursive::views::{Dialog, EditView, Panel, SelectView, TextView};
use cursive::Cursive;
use std::str::FromStr;
@ -74,6 +74,24 @@ fn prompt_for_url(s: &mut Cursive) {
);
}
fn prompt_for_answer(s: &mut Cursive, url: Url, message: String) {
s.add_layer(
Dialog::new()
.title(message)
// Padding is (left, right, top, bottom)
.padding((1, 1, 1, 0))
.content(
EditView::new()
.on_submit(move |s, response| {
let link = format!("{}?query={}", url.to_string(), response);
s.pop_layer();
follow_link(s, &link);
}).fixed_width(60)
)
.with_id("url_query"),
);
}
fn goto_url(s: &mut Cursive, url: &str) {
// Prepend gemini scheme if needed
if url.starts_with("gemini://") {
@ -136,6 +154,8 @@ fn draw_content(s: &mut Cursive, url: Url, content: String) {
let mut main_view = s.find_id::<SelectView>("main").unwrap();
let mut container = s.find_id::<Dialog>("container").unwrap();
let url_copy = url.clone();
// handle response status
if let Some(status_line) = content.lines().next() {
if let Ok(status) = Status::from_str(status_line) {
@ -155,6 +175,9 @@ fn draw_content(s: &mut Cursive, url: Url, content: String) {
));
return;
}
Status::Input(message) => {
prompt_for_answer(s, url_copy, message);
}
other_status => {
s.add_layer(Dialog::info(format!("ERROR: {:?}", other_status)));
return;

Loading…
Cancel
Save