help: add help page
This commit is contained in:
parent
6574048763
commit
396391ea80
|
@ -12,6 +12,7 @@ TODO DONE
|
||||||
view/edit sources
|
view/edit sources
|
||||||
downloads
|
downloads
|
||||||
configuration
|
configuration
|
||||||
|
help page
|
||||||
open last download
|
open last download
|
||||||
actual TOFU
|
actual TOFU
|
||||||
home page
|
home page
|
||||||
|
|
|
@ -35,6 +35,10 @@ Python's standard library.
|
||||||
|
|
||||||
[asn1crypto]: https://github.com/wbond/asn1crypto
|
[asn1crypto]: https://github.com/wbond/asn1crypto
|
||||||
|
|
||||||
|
### Nice keybinds
|
||||||
|
|
||||||
|
A lot of keybinds are defined. Find them in the help page by pressing `?`.
|
||||||
|
|
||||||
### Fun
|
### Fun
|
||||||
|
|
||||||
Link navigation is done by entering the link ID with automatic validation: if
|
Link navigation is done by entering the link ID with automatic validation: if
|
||||||
|
|
|
@ -13,6 +13,7 @@ from bebop.bookmarks import (
|
||||||
from bebop.colors import ColorPair, init_colors
|
from bebop.colors import ColorPair, init_colors
|
||||||
from bebop.command_line import CommandLine
|
from bebop.command_line import CommandLine
|
||||||
from bebop.external import open_external_program
|
from bebop.external import open_external_program
|
||||||
|
from bebop.help import HELP_PAGE
|
||||||
from bebop.history import History
|
from bebop.history import History
|
||||||
from bebop.links import Links
|
from bebop.links import Links
|
||||||
from bebop.mouse import ButtonState
|
from bebop.mouse import ButtonState
|
||||||
|
@ -23,7 +24,26 @@ from bebop.page_pad import PagePad
|
||||||
|
|
||||||
|
|
||||||
class Browser:
|
class Browser:
|
||||||
"""Manage the events, inputs and rendering."""
|
"""Manage the events, inputs and rendering.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
- config: config dict passed to the browser.
|
||||||
|
- stash: certificate stash passed to the browser.
|
||||||
|
- screen: curses stdscr.
|
||||||
|
- dim: current screen dimensions.
|
||||||
|
- page_pad: curses pad containing the current page view.
|
||||||
|
- status_line: curses window used to report current status.
|
||||||
|
- command_line: a CommandLine object for the user to interact with.
|
||||||
|
- running: the browser will continue running while this is true.
|
||||||
|
- status_data: 3-uple of status text, color pair and attributes of the
|
||||||
|
status line, used to reset status after an error.
|
||||||
|
- history: an History object.
|
||||||
|
- cache: a dict containing cached pages
|
||||||
|
- special_pages: a dict containing page names used with "bebop" scheme;
|
||||||
|
values are dicts as well: the "open" key maps to a callable to use when
|
||||||
|
the page is accessed, and the optional "source" key maps to callable
|
||||||
|
returning the page source path.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, config, cert_stash):
|
def __init__(self, config, cert_stash):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
@ -37,6 +57,7 @@ class Browser:
|
||||||
self.status_data = ("", 0, 0)
|
self.status_data = ("", 0, 0)
|
||||||
self.history = History()
|
self.history = History()
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
|
self.special_pages = self.setup_special_pages()
|
||||||
self._current_url = ""
|
self._current_url = ""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -58,6 +79,18 @@ class Browser:
|
||||||
self._current_url = url
|
self._current_url = url
|
||||||
self.set_status(url)
|
self.set_status(url)
|
||||||
|
|
||||||
|
def setup_special_pages(self):
|
||||||
|
"""Return a dict with the special pages functions."""
|
||||||
|
return {
|
||||||
|
"bookmarks": {
|
||||||
|
"open": self.open_bookmarks,
|
||||||
|
"source": lambda: str(get_bookmarks_path())
|
||||||
|
},
|
||||||
|
"help": {
|
||||||
|
"open": self.open_help,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
def run(self, *args, **kwargs):
|
def run(self, *args, **kwargs):
|
||||||
"""Use curses' wrapper around _run."""
|
"""Use curses' wrapper around _run."""
|
||||||
os.environ.setdefault("ESCDELAY", "25")
|
os.environ.setdefault("ESCDELAY", "25")
|
||||||
|
@ -99,7 +132,9 @@ class Browser:
|
||||||
|
|
||||||
def handle_inputs(self):
|
def handle_inputs(self):
|
||||||
char = self.screen.getch()
|
char = self.screen.getch()
|
||||||
if char == ord(":"):
|
if char == ord("?"):
|
||||||
|
self.open_help()
|
||||||
|
elif char == ord(":"):
|
||||||
self.quick_command("")
|
self.quick_command("")
|
||||||
elif char == ord("r"):
|
elif char == ord("r"):
|
||||||
self.reload_page()
|
self.reload_page()
|
||||||
|
@ -287,8 +322,11 @@ class Browser:
|
||||||
from bebop.browser.file import open_file
|
from bebop.browser.file import open_file
|
||||||
open_file(self, parts.path, history=history)
|
open_file(self, parts.path, history=history)
|
||||||
elif parts.scheme == "bebop":
|
elif parts.scheme == "bebop":
|
||||||
if parts.netloc == "bookmarks":
|
special_page = self.special_pages.get(parts.netloc)
|
||||||
self.open_bookmarks()
|
if special_page:
|
||||||
|
special_page["open"]()
|
||||||
|
else:
|
||||||
|
self.set_status_error("Unknown page.")
|
||||||
else:
|
else:
|
||||||
self.set_status_error(f"Protocol {parts.scheme} not supported.")
|
self.set_status_error(f"Protocol {parts.scheme} not supported.")
|
||||||
|
|
||||||
|
@ -458,11 +496,13 @@ class Browser:
|
||||||
directly from their location on disk.
|
directly from their location on disk.
|
||||||
"""
|
"""
|
||||||
delete_source_after = False
|
delete_source_after = False
|
||||||
special_pages = {
|
if self.current_url.startswith("bebop://"):
|
||||||
"bebop://bookmarks": str(get_bookmarks_path())
|
page_name = self.current_url[len("bebop://"):]
|
||||||
}
|
special_pages_functions = self.special_pages.get(page_name)
|
||||||
if self.current_url in special_pages:
|
if not special_pages_functions:
|
||||||
source_filename = special_pages[self.current_url]
|
return
|
||||||
|
get_source = special_pages_functions.get("source")
|
||||||
|
source_filename = get_source() if get_source else None
|
||||||
else:
|
else:
|
||||||
if not self.page_pad.current_page:
|
if not self.page_pad.current_page:
|
||||||
return
|
return
|
||||||
|
@ -472,8 +512,16 @@ class Browser:
|
||||||
source_filename = source_file.name
|
source_filename = source_file.name
|
||||||
delete_source_after = True
|
delete_source_after = True
|
||||||
|
|
||||||
|
if not source_filename:
|
||||||
|
return
|
||||||
|
|
||||||
command = self.config["source_editor"] + [source_filename]
|
command = self.config["source_editor"] + [source_filename]
|
||||||
open_external_program(command)
|
open_external_program(command)
|
||||||
if delete_source_after:
|
if delete_source_after:
|
||||||
os.unlink(source_filename)
|
os.unlink(source_filename)
|
||||||
self.refresh_windows()
|
self.refresh_windows()
|
||||||
|
|
||||||
|
def open_help(self):
|
||||||
|
"""Show the help page."""
|
||||||
|
self.load_page(Page.from_gemtext(HELP_PAGE, self.config["text_width"]))
|
||||||
|
self.current_url = "bebop://help"
|
||||||
|
|
38
bebop/help.py
Normal file
38
bebop/help.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
"""Help page. Currently only keybinds are shown as help."""
|
||||||
|
|
||||||
|
HELP_PAGE = """\
|
||||||
|
# Bebop keybinds
|
||||||
|
|
||||||
|
Keybinds using the SHIFT key are written uppercase. Keybinds using the ALT (or \
|
||||||
|
META) key are written using the "M-" prefix. Symbol keys are written as their \
|
||||||
|
name, not the symbol itself.
|
||||||
|
|
||||||
|
``` list of bebop keybinds
|
||||||
|
- colon: focus the command-line
|
||||||
|
- r: reload page
|
||||||
|
- h: scroll left a bit
|
||||||
|
- j: scroll down a bit
|
||||||
|
- k: scroll up a bit
|
||||||
|
- l: scroll right a bit
|
||||||
|
- H: scroll left a whole page
|
||||||
|
- J: scroll down a whole page
|
||||||
|
- K: scroll up a whole page
|
||||||
|
- L: scroll right a whole page
|
||||||
|
- M-h: scroll one column left
|
||||||
|
- M-j: scroll one line down
|
||||||
|
- M-k: scroll one line up
|
||||||
|
- M-l: scroll one column right
|
||||||
|
- circumflex: horizontally scroll back to the first column
|
||||||
|
- gg: go to the top of the page
|
||||||
|
- G: go to the bottom of the page
|
||||||
|
- o: open an URL
|
||||||
|
- p: go to the previous page
|
||||||
|
- u: go to the parent page (up a level in URL)
|
||||||
|
- U: go to the root page (root URL for the current domain)
|
||||||
|
- b: open bookmarks
|
||||||
|
- B: add current page to bookmarks
|
||||||
|
- e: open the current page source in an editor
|
||||||
|
- digits: go to the corresponding link ID
|
||||||
|
- escape: reset status line text
|
||||||
|
```
|
||||||
|
"""
|
Reference in a new issue