forked from solderpunk/AV-98
display empty files instead of opening them with xdg-open
This commit is contained in:
parent
4e3d3ce62d
commit
9c8693dc09
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## 2.3 - Unreleased
|
## 2.3 - Unreleased
|
||||||
- offpunk/netcache: fix IPv6 as an URL (bug #40)
|
- offpunk/netcache: fix IPv6 as an URL (bug #40)
|
||||||
|
- ansicat: display empty files (instead of opening them with xdg-open)
|
||||||
|
|
||||||
## 2.2 - February 13th 2023
|
## 2.2 - February 13th 2023
|
||||||
- cache folder is now configurable through $OFFPUNK_CACHE_PATH environment variable (by prx)
|
- cache folder is now configurable through $OFFPUNK_CACHE_PATH environment variable (by prx)
|
||||||
|
|
12
ansicat.py
12
ansicat.py
|
@ -727,6 +727,13 @@ class GemtextRenderer(AbstractRenderer):
|
||||||
links += hidden_links
|
links += hidden_links
|
||||||
return r.get_final(), links
|
return r.get_final(), links
|
||||||
|
|
||||||
|
class EmptyRenderer(GemtextRenderer):
|
||||||
|
def get_mime(self):
|
||||||
|
return "text/empty"
|
||||||
|
def prepare(self,body,mode=None):
|
||||||
|
text= "(empty file)"
|
||||||
|
return [[text, "GemtextRenderer"]]
|
||||||
|
|
||||||
class GopherRenderer(AbstractRenderer):
|
class GopherRenderer(AbstractRenderer):
|
||||||
def get_mime(self):
|
def get_mime(self):
|
||||||
return "text/gopher"
|
return "text/gopher"
|
||||||
|
@ -1312,11 +1319,16 @@ _FORMAT_RENDERERS = {
|
||||||
"text/gopher": GopherRenderer,
|
"text/gopher": GopherRenderer,
|
||||||
"image/*": ImageRenderer,
|
"image/*": ImageRenderer,
|
||||||
"application/javascript": HtmlRenderer,
|
"application/javascript": HtmlRenderer,
|
||||||
|
"application/json": HtmlRenderer,
|
||||||
|
"text/empty": EmptyRenderer,
|
||||||
}
|
}
|
||||||
def get_mime(path,url=None):
|
def get_mime(path,url=None):
|
||||||
#Beware, this one is really a shaddy ad-hoc function
|
#Beware, this one is really a shaddy ad-hoc function
|
||||||
if not path:
|
if not path:
|
||||||
return None
|
return None
|
||||||
|
#If the file is empty, simply returns it
|
||||||
|
elif os.path.exists(path) and os.stat(path).st_size == 0:
|
||||||
|
return "text/empty"
|
||||||
elif url and url.startswith("gopher://"):
|
elif url and url.startswith("gopher://"):
|
||||||
#special case for gopher
|
#special case for gopher
|
||||||
#code copy/pasted from netcache
|
#code copy/pasted from netcache
|
||||||
|
|
Loading…
Reference in New Issue
Block a user