Allow multiline query strings

Although Gemini does not imply this, posting small multiline text to server can be of great use.
Some clients (Lagrange) do already support this.
This commit is contained in:
dluciv 2022-02-07 18:55:26 +00:00
parent 265a69a6ed
commit 5afb946160
1 changed files with 16 additions and 1 deletions

17
av98.py
View File

@ -274,7 +274,8 @@ class GeminiClient(cmd.Cmd):
"auto_follow_redirects" : True,
"gopher_proxy" : None,
"tls_mode" : "tofu",
"cache" : False
"cache" : False,
"editor": None
}
self.log = {
@ -445,6 +446,20 @@ you'll be able to transparently follow links to Gopherspace!""")
user_input = getpass.getpass("> ")
else:
user_input = input("> ")
if user_input == "": # Empty input switches to multiline editor
try:
multiline_comment =\
"\n# One line is not enough for your input?" +\
"\n# Then please type & save the whole query, leaving this comment untouched."
with tempfile.NamedTemporaryFile(suffix=".tmp", delete=False) as tfc:
tfc.write(multiline_comment.encode("utf-8"))
subprocess.call([self.options.get("editor", os.environ.get("EDITOR", "vim")), tfc.name])
with open(tfc.name, "r", encoding="utf-8") as tfr:
user_input = tfr.read().strip()
if user_input.endswith(multiline_comment):
user_input = user_input[:-len(multiline_comment)]
finally:
os.unlink(tfc.name)
return self._fetch_over_network(gi.query(user_input))
# Redirects