Remove unecessary duplication of handling code between _handle_gemtext() and _go_to_gi().
This commit is contained in:
parent
e4a44679dc
commit
3aedd549e5
30
av98.py
30
av98.py
|
@ -343,17 +343,24 @@ you'll be able to transparently follow links to Gopherspace!""")
|
|||
self._print_friendly_error(err)
|
||||
return
|
||||
|
||||
# Render gemtext, update index
|
||||
if mime == "text/gemini":
|
||||
self._handle_gemtext(body, gi)
|
||||
|
||||
# Pass file to handler, unless we were asked not to
|
||||
if handle:
|
||||
if mime == "text/gemini":
|
||||
self._handle_gemtext(body, gi)
|
||||
targetfile = self.idx_filename
|
||||
elif gi.scheme == "file":
|
||||
targetfile = gi.path
|
||||
else:
|
||||
cmd_str = self._get_handler_cmd(mime)
|
||||
try:
|
||||
subprocess.call(shlex.split(cmd_str % tmpfile))
|
||||
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.")
|
||||
targetfile = tmpfile
|
||||
cmd_str = self._get_handler_cmd(mime)
|
||||
try:
|
||||
subprocess.call(shlex.split(cmd_str % targetfile))
|
||||
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
|
||||
|
@ -719,7 +726,10 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
|
|||
ui_out.debug("Using handler: %s" % cmd_str)
|
||||
return cmd_str
|
||||
|
||||
def _handle_gemtext(self, body, menu_gi, display=True):
|
||||
def _handle_gemtext(self, body, menu_gi):
|
||||
"""Simultaneously parse and render a text/gemini document.
|
||||
Parsing causes self.index to be populated with GeminiItems.
|
||||
Rendering causes self.idx_filename to contain a rendered view."""
|
||||
self.index = []
|
||||
preformatted = False
|
||||
if self.idx_filename:
|
||||
|
@ -763,10 +773,6 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
|
|||
self.page_index = 0
|
||||
self.index_index = -1
|
||||
|
||||
if display:
|
||||
cmd_str = self._get_handler_cmd("text/gemini")
|
||||
subprocess.call(shlex.split(cmd_str % self.idx_filename))
|
||||
|
||||
def _format_geminiitem(self, index, gi, url=False):
|
||||
protocol = "" if gi.scheme == "gemini" else " %s" % gi.scheme
|
||||
line = "[%d%s] %s" % (index, protocol, gi.name or gi.url)
|
||||
|
|
Loading…
Reference in New Issue