diff --git a/BOARD.txt b/BOARD.txt index a751cd3..3efb0ff 100644 --- a/BOARD.txt +++ b/BOARD.txt @@ -3,7 +3,6 @@ TODO dumb rendering mode per site well, preferences per site maybe? does encoding really work? cf. egsam -add metadata to status bar more UT setup.py @@ -22,12 +21,14 @@ buffers (tabs) a11y? tts? handle soft-hyphens on wrapping bug: combining chars reduce lengths -non shit command-line +use a pad for command-line +use a pad for status bar response code 11 (if still there) gopher? opt. maintain history between sessions history (forward) (useful?) search in page (ugh) +remember scroll pos in history diff --git a/bebop/browser/browser.py b/bebop/browser/browser.py index 6e59945..149bbd1 100644 --- a/bebop/browser/browser.py +++ b/bebop/browser/browser.py @@ -310,6 +310,8 @@ class Browser: self.running = False elif command in ("h", "home"): self.open_home() + elif command in ("i", "info"): + self.show_page_info() return if command in ("o", "open"): self.open_url(words[1]) @@ -657,3 +659,14 @@ class Browser: def open_welcome_page(self): """Open the default welcome page.""" self.open_internal_page("welcome", WELCOME_PAGE) + + def show_page_info(self): + """Show some page informations in the status bar.""" + if not self.page_pad or not self.page_pad.current_page: + return + page = self.page_pad.current_page + mime = page.mime.short if page.mime else "(unknown MIME type)" + encoding = page.encoding or "(unknown encoding)" + size = f"{len(page.source)} chars" + info = f"{mime} {encoding} {size}" + self.set_status(info) diff --git a/bebop/browser/gemini.py b/bebop/browser/gemini.py index 31fc413..fcae206 100644 --- a/bebop/browser/gemini.py +++ b/bebop/browser/gemini.py @@ -216,8 +216,12 @@ def _handle_successful_response(browser: Browser, response: Response, url: str): else: page = Page.from_gemtext(text, browser.config["text_width"]) else: - text = response.content.decode("utf-8", errors="replace") + encoding = "utf-8" + text = response.content.decode(encoding, errors="replace") page = Page.from_text(text) + if page: + page.mime = mime_type + page.encoding = encoding else: download_dir = browser.config["download_path"] filepath = _get_download_path(url, download_dir=download_dir) diff --git a/bebop/help.py b/bebop/help.py index c46a3ee..ade488e 100644 --- a/bebop/help.py +++ b/bebop/help.py @@ -43,9 +43,10 @@ Keybinds using the SHIFT key are written uppercase. Keybinds using the ALT (or M Commands are mostly for actions requiring user input. You can type a command with arguments by pressing the corresponding keybind above. -* o/open : open this URL -* q/quit: well, quit -* h/home: open your home page +* o(pen) : open this URL +* q(uit): well, quit +* h(ome): open your home page +* i(nfo): show page informations * forget_certificate : remove saved fingerprint for this hostname ## Configuration diff --git a/bebop/page.py b/bebop/page.py index e6200a5..500d17e 100644 --- a/bebop/page.py +++ b/bebop/page.py @@ -1,7 +1,9 @@ from dataclasses import dataclass, field +from typing import Optional from bebop.gemtext import parse_gemtext from bebop.metalines import generate_dumb_metalines, generate_metalines +from bebop.mime import MimeType from bebop.links import Links @@ -22,6 +24,8 @@ class Page: metalines: list = field(default_factory=list) links: Links = field(default_factory=Links) title: str = "" + mime: Optional[MimeType] = None + encoding: str = "" @staticmethod def from_gemtext(gemtext: str, wrap_at: int):