Browse Source

Add reload capability

This adds a reload button, with shortcut `r`, that reloads the current
page (if any).  This simply re-fetches the content and redraws the page
(which also resets the cursor position).
openbsd
Arav K 6 years ago committed by Julien Blanchard
parent
commit
26daa0efca
  1. 24
      src/main.rs

24
src/main.rs

@ -29,10 +29,11 @@ mod history;
const HELP: &str = "Welcome to Asuka Gemini browser!
Press g to visit an URL
Press g to visit a URL
Press b to go to the previous URL
Press B to show bookmarks
Press a to add current URL to bookmarks
Press r to reload
Press a to bookmark the current URL
Press q to exit
";
@ -58,6 +59,7 @@ fn main() {
.button("Back (b)", |s| go_back(s))
.button("Go To URL (g)", |s| prompt_for_url(s))
.button("Bookmarks (B)", |s| show_bookmarks(s))
.button("Reload (r)", |s| reload_page(s))
.button("Quit (q)", |s| s.quit())
.with_id("container"),
);
@ -72,6 +74,8 @@ fn main() {
siv.add_global_callback('B', |s| show_bookmarks(s));
// pressing b goes to the previous URL if any
siv.add_global_callback('b', |s| go_back(s));
// pressing r reloads the current URL if any
siv.add_global_callback('r', |s| reload_page(s));
siv.run();
}
@ -164,6 +168,22 @@ fn show_bookmarks(s: &mut Cursive) {
);
}
fn reload_page(s: &mut Cursive) {
// Get current URL from history and revisit it without modifying history
if let Some(url) = history::get_current_url() {
match content::get_data(&url) {
Ok((meta, new_content)) => {
// handle meta header
let response = handle_response_status(s, &url, meta, new_content);
draw_content(s, &url, response);
}
Err(msg) => {
s.add_layer(Dialog::info(msg));
}
}
}
}
fn visit_url(s: &mut Cursive, url: &Url) {
// Close URL popup if any
if s.find_id::<Dialog>("url_popup").is_some() {

Loading…
Cancel
Save