browser: add command to show page info
This commit is contained in:
parent
0dd29c63ae
commit
4738e495b2
|
@ -3,7 +3,6 @@ TODO
|
||||||
dumb rendering mode per site
|
dumb rendering mode per site
|
||||||
well, preferences per site maybe?
|
well, preferences per site maybe?
|
||||||
does encoding really work? cf. egsam
|
does encoding really work? cf. egsam
|
||||||
add metadata to status bar
|
|
||||||
more UT
|
more UT
|
||||||
setup.py
|
setup.py
|
||||||
|
|
||||||
|
@ -22,12 +21,14 @@ buffers (tabs)
|
||||||
a11y? tts?
|
a11y? tts?
|
||||||
handle soft-hyphens on wrapping
|
handle soft-hyphens on wrapping
|
||||||
bug: combining chars reduce lengths
|
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)
|
response code 11 (if still there)
|
||||||
gopher?
|
gopher?
|
||||||
opt. maintain history between sessions
|
opt. maintain history between sessions
|
||||||
history (forward) (useful?)
|
history (forward) (useful?)
|
||||||
search in page (ugh)
|
search in page (ugh)
|
||||||
|
remember scroll pos in history
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,8 @@ class Browser:
|
||||||
self.running = False
|
self.running = False
|
||||||
elif command in ("h", "home"):
|
elif command in ("h", "home"):
|
||||||
self.open_home()
|
self.open_home()
|
||||||
|
elif command in ("i", "info"):
|
||||||
|
self.show_page_info()
|
||||||
return
|
return
|
||||||
if command in ("o", "open"):
|
if command in ("o", "open"):
|
||||||
self.open_url(words[1])
|
self.open_url(words[1])
|
||||||
|
@ -657,3 +659,14 @@ class Browser:
|
||||||
def open_welcome_page(self):
|
def open_welcome_page(self):
|
||||||
"""Open the default welcome page."""
|
"""Open the default welcome page."""
|
||||||
self.open_internal_page("welcome", 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)
|
||||||
|
|
|
@ -216,8 +216,12 @@ def _handle_successful_response(browser: Browser, response: Response, url: str):
|
||||||
else:
|
else:
|
||||||
page = Page.from_gemtext(text, browser.config["text_width"])
|
page = Page.from_gemtext(text, browser.config["text_width"])
|
||||||
else:
|
else:
|
||||||
text = response.content.decode("utf-8", errors="replace")
|
encoding = "utf-8"
|
||||||
|
text = response.content.decode(encoding, errors="replace")
|
||||||
page = Page.from_text(text)
|
page = Page.from_text(text)
|
||||||
|
if page:
|
||||||
|
page.mime = mime_type
|
||||||
|
page.encoding = encoding
|
||||||
else:
|
else:
|
||||||
download_dir = browser.config["download_path"]
|
download_dir = browser.config["download_path"]
|
||||||
filepath = _get_download_path(url, download_dir=download_dir)
|
filepath = _get_download_path(url, download_dir=download_dir)
|
||||||
|
|
|
@ -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.
|
Commands are mostly for actions requiring user input. You can type a command with arguments by pressing the corresponding keybind above.
|
||||||
|
|
||||||
* o/open <url>: open this URL
|
* o(pen) <url>: open this URL
|
||||||
* q/quit: well, quit
|
* q(uit): well, quit
|
||||||
* h/home: open your home page
|
* h(ome): open your home page
|
||||||
|
* i(nfo): show page informations
|
||||||
* forget_certificate <hostname>: remove saved fingerprint for this hostname
|
* forget_certificate <hostname>: remove saved fingerprint for this hostname
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from bebop.gemtext import parse_gemtext
|
from bebop.gemtext import parse_gemtext
|
||||||
from bebop.metalines import generate_dumb_metalines, generate_metalines
|
from bebop.metalines import generate_dumb_metalines, generate_metalines
|
||||||
|
from bebop.mime import MimeType
|
||||||
from bebop.links import Links
|
from bebop.links import Links
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +24,8 @@ class Page:
|
||||||
metalines: list = field(default_factory=list)
|
metalines: list = field(default_factory=list)
|
||||||
links: Links = field(default_factory=Links)
|
links: Links = field(default_factory=Links)
|
||||||
title: str = ""
|
title: str = ""
|
||||||
|
mime: Optional[MimeType] = None
|
||||||
|
encoding: str = ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_gemtext(gemtext: str, wrap_at: int):
|
def from_gemtext(gemtext: str, wrap_at: int):
|
||||||
|
|
Reference in a new issue