diff --git a/bebop/browser.py b/bebop/browser.py index 3a81e5e..593bfae 100644 --- a/bebop/browser.py +++ b/bebop/browser.py @@ -6,6 +6,7 @@ import os from bebop.colors import ColorPair, init_colors from bebop.command_line import (CommandLine, EscapeCommandInterrupt, TerminateCommandInterrupt) +from bebop.history import History from bebop.mouse import ButtonState from bebop.navigation import join_url, parse_url, sanitize_url, set_parameter from bebop.page import Page @@ -24,7 +25,7 @@ class Browser: self.command_line = None self.status_data = ("", 0) self.current_url = "" - self.history = [] + self.history = History() @property def h(self): @@ -414,5 +415,5 @@ class Browser: def go_back(self): """Go back in history if possible.""" - if self.history: + if self.history.has_links(): self.open_gemini_url(self.history.pop(), history=False) diff --git a/bebop/history.py b/bebop/history.py new file mode 100644 index 0000000..2809286 --- /dev/null +++ b/bebop/history.py @@ -0,0 +1,17 @@ +class History: + + def __init__(self): + self.urls = [] + + def has_links(self): + """Return True if there is at least one URL in the history.""" + return bool(self.urls) + + def push(self, url): + """Add an URL to the history.""" + if not self.urls or self.urls[-1] != url: + self.urls.append(url) + + def pop(self): + """Return latest URL added to history and remove it.""" + return self.urls.pop()