Files
Bolt/core/prompt.py

21 lines
479 B
Python
Raw Normal View History

2018-12-30 03:07:15 +05:30
import os
import tempfile
2019-04-25 01:29:54 +05:30
2018-12-30 03:07:15 +05:30
def prompt(default=None):
editor = 'nano'
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)
2019-04-25 01:29:54 +05:30
return tmpfile.read().strip()