Broken project to implement a cross-protocol browser in textual
back button: implement functionality
| -rwxr-xr-x | browset.py | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -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() |