summary refs log tree commit diff
path: root/browset.py
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2023-01-02 12:53:29 -0500
committerZach DeCook <zachdecook@librem.one>2023-01-02 12:53:29 -0500
commit3a6a39730df0a6b0d6efa4f8606824b3a61322cf (patch)
treeb4481b55453fccf87e559b7b01ae4eaadf381a89 /browset.py
parent339b5d37a7b347f213b8f817d24939916bbf0b34 (diff)
downloadbrowset-3a6a39730df0a6b0d6efa4f8606824b3a61322cf.tar.gz
back button: implement functionality
Diffstat (limited to 'browset.py')
-rwxr-xr-xbrowset.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/browset.py b/browset.py
index f812acc..30d51b3 100755
--- a/browset.py
+++ b/browset.py
@@ -13,14 +13,15 @@ class Browset(App):
     BINDINGS = [
         Binding("ctrl+c,ctrl+q", "app.quit", "Quit", show=True),
     ]
+    history = []
 
     content = ["#h1", "## hey [b]Is this unformatted?[/b]", "```startpre","in preformatted text this hsould have a scrollbar if it is too wide oh yeah tonight is gonna be great.", "``` (ended pre)", "afterward"]
     def compose(self) -> ComposeResult:
         yield Footer()
         yield Container(
-            Button("🔙"), # ⏪
+            Button("🔙", variant='primary', name='back'), # ⏪
             Button("🔝", name='../'), # ⏫
-            Button("🔜"), # ⏩
+            Button("🔜", variant='primary', name='soon'), # ⏩
             Button("🔄", variant='primary', name='refresh'), # 🔁
             
             Input(placeholder="Enter URI", id="url"),
@@ -28,21 +29,27 @@ class Browset(App):
         )
         yield Gemtext(fp=self.content, id="content")
     async def on_input_submitted(self, message: Input.Submitted) -> None:
-        self._do_url(message.value)
+        self._do_url(message.value, setbar=False)
 
     async def on_button_pressed(self, event: Button.Pressed) -> None:
       if event.button.variant == 'primary':
-        if event.button.name == "refresh":
+        if event.button.name == 'refresh':
             self._do_url(self.url)
+        elif event.button.name == 'back':
+          if len(self.history):
+            self._do_url(self.history.pop(), histore=False)
       else:
         url = event.button.name
         if not ":" in url:
             url = GeminiProtocol.relativeURL(url, self.url)
-        input = self.query_one("#url")
-        input.value = url
         self._do_url(url)
         
-    def _do_url(self, url):
+    def _do_url(self, url, histore=True, setbar=True):
+        if setbar:
+            input = self.query_one("#url")
+            input.value = url
+        if histore:
+            self.history.append(self.url)
         self.url = url
         (mime, fp) = GeminiProtocol.get(url)
         self.query_one("#content").remove()