~julienxx/asuka

Add reload capability v1 APPLIED

Arav K: 1
 Add reload capability

 1 files changed, 22 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~julienxx/asuka/patches/13902/mbox | git am -3
Learn more about email & git

[PATCH v1] Add reload capability Export this patch

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).
---
Tested.

 src/main.rs | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 50280a0..e398836 100644
--- a/src/main.rs
+++ b/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() {
-- 
2.28.0