diff --git a/ansirenderer.py b/ansirenderer.py old mode 100644 new mode 100755 diff --git a/offpunk.py b/offpunk.py index e29302e..92a31c2 100755 --- a/offpunk.py +++ b/offpunk.py @@ -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: diff --git a/opnk.py b/opnk.py new file mode 100644 index 0000000..e201cb5 --- /dev/null +++ b/opnk.py @@ -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 don’t try to open in the terminal, + #we immediately fallback to xdg-open. + #netcache currently provide the path if it’s 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()