This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH v1] Create a `History` structure

Message ID
DKIM signature
Download raw message
Patch: +52 -19
The goal is to move the history data out of global state and into the
user-data area provided by `cursive`.  This begins that process by
creating a self-contained structure for manipulating history.  For now,
the original module functions are provided.  Once the history structure
is embedded as user data, they will no longer be necessary.

This also changes behaviour slightly, by allowing all URLs in the
history stack to be popped off, thereby returning to the start page.
However, the content loading and drawing functions don't yet support
this, so nothing changes on the user end.
 src/history.rs | 69 +++++++++++++++++++++++++++++++++++++-------------
 src/main.rs    |  2 +-
 2 files changed, 52 insertions(+), 19 deletions(-)

diff --git a/src/history.rs b/src/history.rs
index 7883697..5375280 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -1,32 +1,65 @@
use std::sync::Mutex;
use url::Url;

/// History.
/// This structure manages all aspects of browser history.
/// Internally, URLs are stored in a first-in-last-out (FILO) stack.
/// When a URL is visited, it gets pushed on top of the stack.  To go
/// back, the topmost URL (i.e. the current one) is popped off, and
/// the previous URL becomes the current URL.  Initially, the stack is
/// empty, signifying that the current page is the startup page.
pub struct History {
    /// The URL stack.
    urls: Vec<Url>,

impl History {
    /// Creates a new, empty [`History`].
    pub fn new() -> History {
        History { urls: Vec::new() }

    /// Retrieves the current URL, if any.
    pub fn cur(&self) -> Option<&Url> {

    /// Pushes a new URL onto the stack.
    /// This indicates that this new URL is being visited.
    pub fn push(&mut self, url: Url) {

    /// Pops off the current URL, if any.
    /// This indicates that the previous URL is being visited.
    /// The current URL (if any) is lost.
    /// If there is only one URL on the stack, it gets removed.  If
    /// the stack is already empty, no action occurs.
    pub fn pop(&mut self) {

lazy_static! {
    static ref HISTORY: Mutex<Vec<Url>> = Mutex::new(vec![]);
    static ref HISTORY: Mutex<History> = Mutex::new(History::new());

pub fn append(url: &str) {
    let url = Url::parse(url).unwrap();
pub fn append(url: Url) {

pub fn get_current_url() -> Option<Url> {
    let history = HISTORY.lock().unwrap();

pub fn get_previous_url() -> Option<Url> {
    let mut history = HISTORY.lock().unwrap();

    if history.len() > 1 {
        history.pop(); // remove current

        if history.len() > 1 {
            history.pop() // return previous
        } else {
    } else {
diff --git a/src/main.rs b/src/main.rs
index e398836..a8c2087 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -192,7 +192,7 @@ fn visit_url(s: &mut Cursive, url: &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);
Reply to thread Export thread (mbox)