diff --git a/CHANGELOG b/CHANGELOG index 81d0ffc..4a56428 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ # Offpunk History -## 1.0 - Unreleased +## 1.0 - March 14th 2022 +- Default width is now the standard 72 - Content and pictures now centered for more elegant reading - "less" has been renamed "view" - "view feed" and "view feeds" to see the first/all feeds on a HTML page diff --git a/README.md b/README.md index d69480f..1db6dc7 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Offpunk is a single python file. Installation is optional, you can simply downlo You use the `go` command to visit a URL, e.g. `go gemini.circumlunar.space`. (gemini:// is assumed is no protocol is specified. Supported protocols are gemini, gopher, http, https, mailto, spartan and file). -Links in pages are assigned numerical indices. Just type an index to follow that link. If page is too long to fit on your screen, the content is displayed in the less pager (by default). Type `q` to quit and go back to Offpunk prompt. Type `view` or `v` to display it again. (`view full` or `v full` allows to see the full html page instead of the article view. `v feed` try to display the linked RSS feed and `v feeds`display a list of available fedes. This only applies to html pages) +Links in pages are assigned numerical indices. Just type an index to follow that link. If page is too long to fit on your screen, the content is displayed in the less pager (by default). Type `q` to quit and go back to Offpunk prompt. Type `view` or `v` to display it again. (`view full` or `v full` allows to see the full html page instead of the article view. `v feed` try to display the linked RSS feed and `v feeds` displays a list of available feeds. This only applies to html pages) Use `add` to add a capsule to your bookmarks and `bookmarks` or `bm` to show your bookmarks (you can create multiple bookmarks lists, edit and remove them. See the `list` manual with `help list`). @@ -67,7 +67,7 @@ Announces about Offpunk will be made on Ploum’s Gemlog => gemini://rawtext.cl Offpunk has no "strict dependencies", i.e. it should run and work without anything else beyond the Python standard library and the "less" pager. However, it will "opportunistically import" a few other libraries if they are available to offer an improved -experience or some other features. Python libraries requests, bs4 and readabliity are required for http/html support. +experience or some other features. Python libraries requests, bs4 and readability are required for http/html support. Images are displayed if python-ansiwrap and chafa are presents (python-pil is needed for chafa version before 1.10). To avoid using unstable or too recent libraries, the rule of thumb is that a library should be packaged in Debian/Ubuntu. Keep in mind that Offpunk is mainly tested will all libraries installed. If you encounter a crash without one optional dependencies, please report it. @@ -82,11 +82,11 @@ Run command `version` in offpunk to see if you are missing some dependencies. * The [cryptography library](https://pypi.org/project/cryptography/) will provide a better and slightly more secure experience when using the default TOFU certificate validation mode and is highly recommended (apt-get install python3-cryptography). -* [Python magic](https://github.com/ahupp/python-magic/) is useful to determine the MIME type of cached object. If not present, the file extension will be used but some capsules provide wrong extension or no extension at all. (apt-get install python3-magic) +* [Python magic](https://github.com/ahupp/python-magic/) is useful to determine the MIME type of cached object. If not present, the file extension will be used but some capsules provide wrong extension or no extension at all. Python-magic is highly recommended. (apt-get install python3-magic) * [Python editor](https://github.com/fmoo/python-editor) is used to edit your lists with "list edit". (apt-get install python3-editor) * [Xsel](http://www.vergenet.net/~conrad/software/xsel/) allows to `go` to the URL copied in the clipboard without having to paste it (both X and traditional clipboards are supported). Also needed to use the `copy` command. (apt-get install xsel) * [Chafa](https://hpjansson.org/chafa/) allows to display pictures in your console. Install it and browse to an HTML page with picture to see the magic. -* [Python-pil](http://python-pillow.github.io/) is required to only display the first frame of animated gif with chafa. +* [Python-pil](http://python-pillow.github.io/) is required to only display the first frame of animated gif with chafa if chafa version is lower than 1.10. * [Python-setproctitle](https://github.com/dvarrazzo/py-setproctitle) will change the process name from "python" to "offpunk". Useful to kill it without killing every python service. ## Features diff --git a/offpunk.py b/offpunk.py index 0a44c73..b00b15a 100755 --- a/offpunk.py +++ b/offpunk.py @@ -12,7 +12,7 @@ # - Björn Wärmedal # - -_VERSION = "0.9" +_VERSION = "1.0" import argparse import cmd @@ -81,12 +81,16 @@ def term_width(): # return wrapped text as a list of lines def wraplines(*args,**kwargs): # print("will wrap with %s and %s"%(str(args),str(kwargs))) + if "center" in kwargs: + center = kwargs.pop("center") + else: + center = True lines = wrap_method(*args,**kwargs) lines2 = [] textwidth = TERM_WIDTH termspace = shutil.get_terminal_size()[0] #Following code instert blanck spaces to center the content - if termspace > textwidth: + if center and termspace > textwidth: margin = int((termspace - textwidth)//2) else: margin = 0 @@ -668,7 +672,7 @@ class FeedRenderer(GemtextRenderer): if mode == "full": if "summary" in i: rendered, links = HtmlRenderer.render(self,i.summary,\ - width=width,mode="full",add_title=False) + width=width,mode="full",add_title=False,center=False) page += rendered page += "\n" return page @@ -742,7 +746,7 @@ class HtmlRenderer(AbstractRenderer): # Our own HTML engine (crazy, isn’t it?) # Return [rendered_body, list_of_links] # 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,center=True): if not width: width = term_width() if not _DO_HTML: @@ -843,7 +847,7 @@ class HtmlRenderer(AbstractRenderer): # support for images nested in links for child in element.children: if child.name == "img": - # recursive rendering seems to displaying images twice + # recursive rendering seems to display some images twice img = recursive_render(child) #src = child.get("src") #img = render_image(src,width=width,mode=mode) @@ -916,7 +920,7 @@ class HtmlRenderer(AbstractRenderer): if line.strip() != "": try: wrapped = wrapparagraph(line,width,initial_indent=i_indent, - subsequent_indent=s_indent) + subsequent_indent=s_indent,center=center) except Exception as err: wrapped = line wrapped += "\n" @@ -2807,13 +2811,14 @@ Marks are temporary until shutdown (not saved to disk).""" output += " - python-setproctitle : " + has(_HAS_SETPROCTITLE) output += " - xdg-open : " + has(_HAS_XDGOPEN) output += " - xsel : " + has(_HAS_XSEL) - output += " - chafa : " + has(_HAS_CHAFA) - output += " Only one needed amongst the followings :\n" - output += " - chafa >= 1.10.0 : " + has(_NEW_CHAFA) - output += " - python-pil : " + has(_HAS_PIL) + if _NEW_CHAFA: + output += " - chafa 1.10+ : " + has(_HAS_CHAFA) + else: + output += " - chafa : " + has(_HAS_CHAFA) + output += " - python-pil : " + has(_HAS_PIL) output += "\nFeatures :\n" - output += " - Render images (ansiwrap,chafa, pil|chafa > 1.10) : " + has(_RENDER_IMAGE) + output += " - Render images (ansiwrap,chafa, pil|chafa 1.10+ ) : " + has(_RENDER_IMAGE) output += " - Render HTML (bs4, readability) : " + has(_DO_HTML) output += " - Render Atom/RSS feeds (feedparser) : " + has(_DO_FEED) output += " - Connect to http/https (requests) : " + has(_DO_HTTP) @@ -2883,6 +2888,8 @@ Use "view feeds" to see available feeds on this page. subs = self.gi.get_subscribe_links() if len(subs) > 1: self.do_go(subs[1][0]) + elif "rss" in subs[0][1] or "atom" in subs[0][1]: + print("%s is already a feed" %self.gi.url) else: print("No other feed found on %s"%self.gi.url) elif args[0] == "feeds": @@ -3051,6 +3058,8 @@ To unsubscribe, remove the page from the "subscribed" list.""" subs = self.gi.get_subscribe_links() if len(subs) > 1: stri = "Multiple feeds have been found :\n" + elif "rss" in subs[0][1] or "atom" in subs[0][1] : + stri = "This page is already a feed:\n" else: stri = "No feed detected. You can still watch the page :\n" counter = 0 diff --git a/setup.py b/setup.py index d099049..4ff1853 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='offpunk', - version='0.9', + version='1.0', description="Offline Command line Gemini client forked from AV-98.", author="Ploum", author_email="offpunk@ploum.eu",