Rejig how do_bookmark() handles an argument to simplify go_to_gi().

This commit is contained in:
Solderpunk 2023-11-15 18:29:52 +01:00
parent d2fe381c3e
commit 480f2cc15f
1 changed files with 16 additions and 11 deletions

27
av98.py
View File

@ -297,7 +297,7 @@ class GeminiClient(cmd.Cmd):
ui_out.debug("Raw buffer: ", self.raw_file_buffer)
ui_out.debug("Rendered buffer: ", self.rendered_file_buffer)
def _go_to_gi(self, gi, update_hist=True, check_cache=True, handle=True):
def _go_to_gi(self, gi, update_hist=True, check_cache=True):
"""This method might be considered "the heart of AV-98".
Everything involved in fetching a gemini resource happens here:
sending the request over the network, parsing the response if
@ -355,14 +355,13 @@ you'll be able to transparently follow links to Gopherspace!""")
else:
self.active_rendered_file = self.active_raw_file
# Pass file to handler, unless we were asked not to
if handle:
cmd_str = self._get_handler_cmd(mime)
try:
subprocess.call(shlex.split(cmd_str % self.active_rendered_file))
except FileNotFoundError:
print("Handler program %s not found!" % shlex.split(cmd_str)[0])
print("You can use the ! command to specify another handler program or pipeline.")
# Pass file to handler
cmd_str = self._get_handler_cmd(mime)
try:
subprocess.call(shlex.split(cmd_str % self.active_rendered_file))
except FileNotFoundError:
print("Handler program %s not found!" % shlex.split(cmd_str)[0])
print("You can use the ! command to specify another handler program or pipeline.")
# Update state
self.gi = gi
@ -1368,10 +1367,16 @@ Bookmarks are stored using the 'add' command."""
print("bookmarks command takes a single integer argument!")
return
gi = GeminiItem("file://" + os.path.abspath(bm_file))
self._go_to_gi(gi, update_hist=False, handle = not args)
if args:
# Use argument as a numeric index
# Semi-sneaky
# Parses the bookmark file and modifies self.index so that
# self.default(n) works, but avoids invoking a handler so the
# full bookmark list is never seen.
self.active_raw_file = gi.path
self._handle_gemtext(gi)
self.default(line)
else:
self._go_to_gi(gi, update_hist=False)
### Help
def do_help(self, arg):