introducing openk

This commit is contained in:
Lionel Dricot 2023-08-04 19:09:48 +02:00
parent 2e02d06b0e
commit 3155585c9e
3 changed files with 39 additions and 15 deletions

0
ansirenderer.py Normal file → Executable file
View File

View File

@ -143,21 +143,6 @@ def fix_ipv6_url(url):
return schema + "://" + schemaless
return schemaless
# Offpunk is basically a GeminiClient class which download URLs using netcache then
# display them using AnsiRenderer.
class GeminiItem():
def __init__(self, url, name=""):
self.last_mode = None
url = netcache.normalize_url(url)
self.url = fix_ipv6_url(self.url).strip()
self.name = name
self.mime = None
self.renderer = ansirenderer.renderer_from_file(netcache.get_cache_path(self.url),self.url)
self.scheme = "https"
self.local = False
# Cheap and cheerful URL detector
def looks_like_url(word):
try:

39
opnk.py Normal file
View File

@ -0,0 +1,39 @@
#!/bin/python
#opnk stand for "Open like a PuNK".
#It will open any file or URL and display it nicely in less.
#If not possible, it will fallback to xdg-open
#URL are retrieved through netcache
import netcache
import offutils
class opencache():
def __init__(self):
self.temp_files = {}
self.rendererdic = {}
def opnk(inpath,terminal=True):
#if terminal = False, we dont try to open in the terminal,
#we immediately fallback to xdg-open.
#netcache currently provide the path if its a file.
#may this should be migrated here.
path = netcache.get_cache_path(inpath)
#TODO: migrate here ansirenderer display
1. À partir du path, tenter le ansirenderer
2. Sauver le rendu dans self.temp_files[mode] (donc le mode doit être passé à opnk)
3. Sauver le renderer dans self.rendererdic
3. Donner à less
4. sinon, donner à xdg-open
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("content",metavar="INPUT", nargs="*", type=argparse.FileType("r"),
default=sys.stdin, help="Path to the file or URL to open")
args = parser.parse_args()
cache = opencache()
for f in args.content:
cache.opnk(f)
if __name__ == "__main__":
main()