fixing a tour bug and making the width dynamic
This commit is contained in:
parent
430943a9b3
commit
4fa3a718a8
|
@ -5,7 +5,7 @@ UPGRADE: Users who subscribed to pages before 0.4 should run once the command "l
|
||||||
- New list command : "list freeze" and "list suscribe"
|
- New list command : "list freeze" and "list suscribe"
|
||||||
- Pictures are now displayed directely in terminal (suggested by kelbot)
|
- Pictures are now displayed directely in terminal (suggested by kelbot)
|
||||||
- Introducing the "open" command to open current page/image/file with external handler.
|
- Introducing the "open" command to open current page/image/file with external handler.
|
||||||
- "set width XX" will now work everywhere (thanks kelbot for reporting the bug)
|
- "set width XX" now works to set the max width. If smaller, terminal width is used (thanks kelbot for reporting the bug)
|
||||||
- RSS feeds are now rendered as Gemlogs to improve consistency while browsing
|
- RSS feeds are now rendered as Gemlogs to improve consistency while browsing
|
||||||
- Improved syncing performances and multiple bug/crash fixes.
|
- Improved syncing performances and multiple bug/crash fixes.
|
||||||
|
|
||||||
|
|
29
offpunk.py
29
offpunk.py
|
@ -205,6 +205,13 @@ urllib.parse.uses_netloc.append("gemini")
|
||||||
global TERM_WIDTH
|
global TERM_WIDTH
|
||||||
TERM_WIDTH = 80
|
TERM_WIDTH = 80
|
||||||
|
|
||||||
|
def term_width():
|
||||||
|
width = TERM_WIDTH
|
||||||
|
cur = shutil.get_terminal_size()[0] - 1
|
||||||
|
if cur < width:
|
||||||
|
width = cur
|
||||||
|
return width
|
||||||
|
|
||||||
def fix_ipv6_url(url):
|
def fix_ipv6_url(url):
|
||||||
if not url:
|
if not url:
|
||||||
return
|
return
|
||||||
|
@ -265,7 +272,7 @@ class AbstractRenderer():
|
||||||
|
|
||||||
def get_body(self,readable=True,width=None):
|
def get_body(self,readable=True,width=None):
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = term_width()
|
||||||
if self.rendered_text == None or not readable:
|
if self.rendered_text == None or not readable:
|
||||||
if readable :
|
if readable :
|
||||||
mode = "readable"
|
mode = "readable"
|
||||||
|
@ -306,7 +313,7 @@ class GemtextRenderer(AbstractRenderer):
|
||||||
#render_gemtext
|
#render_gemtext
|
||||||
def render(self,gemtext, width=None,mode=None):
|
def render(self,gemtext, width=None,mode=None):
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = term_width()
|
||||||
links = []
|
links = []
|
||||||
preformatted = False
|
preformatted = False
|
||||||
rendered_text = ""
|
rendered_text = ""
|
||||||
|
@ -383,7 +390,7 @@ class GopherRenderer(AbstractRenderer):
|
||||||
#menu_or_text
|
#menu_or_text
|
||||||
def render(self,body,width=None,mode=None):
|
def render(self,body,width=None,mode=None):
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = term_width()
|
||||||
try:
|
try:
|
||||||
render,links = self._render_goph(width=width,mode=mode)
|
render,links = self._render_goph(width=width,mode=mode)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -397,7 +404,7 @@ class GopherRenderer(AbstractRenderer):
|
||||||
|
|
||||||
def _render_goph(self,width=None,mode=None):
|
def _render_goph(self,width=None,mode=None):
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = term_width()
|
||||||
# This is copied straight from Agena (and thus from VF1)
|
# This is copied straight from Agena (and thus from VF1)
|
||||||
rendered_text = ""
|
rendered_text = ""
|
||||||
links = []
|
links = []
|
||||||
|
@ -515,7 +522,7 @@ class FeedRenderer(GemtextRenderer):
|
||||||
|
|
||||||
def prepare(self,content,mode="readable",width=None):
|
def prepare(self,content,mode="readable",width=None):
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = term_width()
|
||||||
self.links = []
|
self.links = []
|
||||||
self.title = "RSS/Atom feed"
|
self.title = "RSS/Atom feed"
|
||||||
page = ""
|
page = ""
|
||||||
|
@ -577,7 +584,7 @@ class ImageRenderer(AbstractRenderer):
|
||||||
if mode == "links_only":
|
if mode == "links_only":
|
||||||
return "", []
|
return "", []
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = term_width()
|
||||||
try:
|
try:
|
||||||
img_obj = Image.open(img)
|
img_obj = Image.open(img)
|
||||||
if hasattr(img_obj,"n_frames") and img_obj.n_frames > 1:
|
if hasattr(img_obj,"n_frames") and img_obj.n_frames > 1:
|
||||||
|
@ -604,7 +611,7 @@ class HtmlRenderer(AbstractRenderer):
|
||||||
# mode is either links_only, readable or full
|
# mode is either links_only, readable or full
|
||||||
def render(self,body,mode="readable",width=None,add_title=True):
|
def render(self,body,mode="readable",width=None,add_title=True):
|
||||||
if not width:
|
if not width:
|
||||||
width = TERM_WIDTH
|
width = term_width()
|
||||||
if not _DO_HTML:
|
if not _DO_HTML:
|
||||||
print("HTML document detected. Please install python-bs4 and python-readability.")
|
print("HTML document detected. Please install python-bs4 and python-readability.")
|
||||||
return
|
return
|
||||||
|
@ -1036,7 +1043,7 @@ class GeminiItem():
|
||||||
title += " (%s links) \x1b[0;31m(last accessed on %s)"%(nbr,str_last)
|
title += " (%s links) \x1b[0;31m(last accessed on %s)"%(nbr,str_last)
|
||||||
rendered_title = "\x1b[31m\x1b[1m"+ title + "\x1b[0m"
|
rendered_title = "\x1b[31m\x1b[1m"+ title + "\x1b[0m"
|
||||||
#FIXME: width to replace self.options["width"]
|
#FIXME: width to replace self.options["width"]
|
||||||
wrapped = textwrap.fill(rendered_title,TERM_WIDTH)
|
wrapped = textwrap.fill(rendered_title,term_width())
|
||||||
return wrapped + "\n"
|
return wrapped + "\n"
|
||||||
|
|
||||||
def _set_renderer(self,mime=None):
|
def _set_renderer(self,mime=None):
|
||||||
|
@ -2458,8 +2465,9 @@ Current tour can be listed with `tour ls` and scrubbed with `tour clear`."""
|
||||||
if len(self.list_get_links("tour")) < 1:
|
if len(self.list_get_links("tour")) < 1:
|
||||||
print("End of tour.")
|
print("End of tour.")
|
||||||
else:
|
else:
|
||||||
self.list_go_to_line("1","tour")
|
url = self.list_go_to_line("1","tour")
|
||||||
self.list_rm_url(self.gi.url,"tour")
|
if url:
|
||||||
|
self.list_rm_url(url,"tour")
|
||||||
elif line == "ls":
|
elif line == "ls":
|
||||||
self.list_show("tour")
|
self.list_show("tour")
|
||||||
elif line == "clear":
|
elif line == "clear":
|
||||||
|
@ -2881,6 +2889,7 @@ archives, which is a special historical list limited in size. It is similar to `
|
||||||
gi = gi.get_link(int(line))
|
gi = gi.get_link(int(line))
|
||||||
display = not self.sync_only
|
display = not self.sync_only
|
||||||
self._go_to_gi(gi,handle=display)
|
self._go_to_gi(gi,handle=display)
|
||||||
|
return gi.url
|
||||||
|
|
||||||
def list_show(self,list):
|
def list_show(self,list):
|
||||||
list_path = self.list_path(list)
|
list_path = self.list_path(list)
|
||||||
|
|
Loading…
Reference in New Issue