Skip to content

Commit

Permalink
interactive prompt for getting user input
Browse files Browse the repository at this point in the history
  • Loading branch information
s0md3v authored Oct 24, 2018
1 parent 7bc7aba commit 41f7f8c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import tempfile

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)
return tmpfile.read().strip()

0 comments on commit 41f7f8c

Please sign in to comment.