2018-10-27 18:58:52 +05:30
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
def prompt(default=None):
|
2018-11-12 08:15:33 +01:00
|
|
|
editor = os.environ.get("EDITOR", "nano")
|
2018-10-27 18:58:52 +05:30
|
|
|
with tempfile.NamedTemporaryFile(mode='r+') as tmpfile:
|
|
|
|
|
if default:
|
|
|
|
|
tmpfile.write(default)
|
|
|
|
|
tmpfile.flush()
|
|
|
|
|
|
|
|
|
|
child_pid = os.fork()
|
|
|
|
|
is_child = child_pid == 0
|
|
|
|
|
|
|
|
|
|
if is_child:
|
|
|
|
|
os.execvp(editor, [editor, tmpfile.name])
|
|
|
|
|
else:
|
|
|
|
|
os.waitpid(child_pid, 0)
|
|
|
|
|
tmpfile.seek(0)
|
2018-11-12 08:15:33 +01:00
|
|
|
return tmpfile.read().strip()
|