Allow multiline query strings #39
17
av98.py
17
av98.py
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue