diff --git a/CHANGELOG b/CHANGELOG index ebb9a0c..31eef8c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,11 +1,13 @@ # Offpunk History ## 1.3 - Unreleased +- Removed dependency to python editor. If no $VISUAL or $EDITOR, please use "set editor" in Offpunk. - New behaviour for "find" (or "/") which is to grep through current page (ripgrep used if detected) - Default width set to 80 as many gopherhole and gemini capsule have it hardcoded - Streaming URL without valid content-length are now closed after 5Mo of download (thanks to Eoin Carney for reporting the issue) - Fixed a crash when the cache is already a dir inside a dir. - Fixed a crash when manually entering an unknown gopher URL while offline +- Fixed an error with older less version ## 1.2 - March 24th 2022 Very experimental release: diff --git a/README.md b/README.md index 384926c..e5c8dc1 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,6 @@ Run command `version` in offpunk to see if you are missing some dependencies. 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. 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". Removing this dependency is on the roadmap (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. * [Timg](https://github.com/hzeller/timg) is a slower alternative to chafa for inline images. But it has better rendering when displaying only the image. Install both to get the best of both world but if you need to choose one, choose Chafa. diff --git a/offpunk.py b/offpunk.py index d698b3d..8c5cace 100755 --- a/offpunk.py +++ b/offpunk.py @@ -53,12 +53,6 @@ try: except ModuleNotFoundError: _HAS_SETPROCTITLE = False -try: - import editor - _HAS_EDITOR = True -except ModuleNotFoundError: - _HAS_EDITOR = False - import textwrap global TERM_WIDTH @@ -1835,6 +1829,7 @@ class GeminiClient(cmd.Cmd): "archives_size" : 200, "history_size" : 200, "max_size_download" : 10, + "editor" : None, } global TERM_WIDTH TERM_WIDTH = self.options["width"] @@ -3123,7 +3118,6 @@ Marks are temporary until shutdown (not saved to disk).""" return "\t\x1b[1;31mNot Installed\x1b[0m\n" output = "Offpunk " + _VERSION + "\n" output += "===========\n" - output += " - python-editor : " + has(_HAS_EDITOR) output += " - python-cryptography : " + has(_HAS_CRYPTOGRAPHY) output += " - python-magic : " + has(_HAS_MAGIC) output += " - python-requests : " + has(_DO_HTTP) @@ -3701,16 +3695,28 @@ Note: There’s no "delete" on purpose. The use of "archive" is recommended.""" else: print("A name is required to create a new list. Use `list create NAME`") elif args[0] == "edit": - if not _HAS_EDITOR: - print("Please install python-editor to edit you lists") - elif len(args) > 1: - if args[1] in self.list_lists(): + editor = None + if "editor" in self.options and self.options["editor"]: + editor = self.options["editor"] + elif os.environ.get("VISUAL"): + editor = os.environ.get("VISUAL") + elif os.environ.get("EDITOR"): + editor = os.environ.get("EDITOR") + if editor: + if len(args) > 1 and args[1] in self.list_lists(): path = os.path.join(listdir,args[1]+".gmi") - editor.edit(path) + try: + subprocess.call("%s %s"%(editor,path),shell=True) + except Exception as err: + print(err) + print("Please set a valid editor with \"set editor\"") else: print("A valid list name is required to edit a list") else: - print("A valid list name is required to edit a list") + print("No valid editor has been found.") + print("You can use the following command to set your favourite editor:") + print("set editor EDITOR") + print("or use the $VISUAL or $EDITOR environment variables.") elif args[0] == "delete": if len(args) > 1: if self.list_is_system(args[1]):