create/edit tickets in a text editor

This commit is contained in:
Romain Bignon 2014-01-21 23:13:39 +01:00
commit 2b0d4e8b91
2 changed files with 163 additions and 68 deletions

View file

@ -453,15 +453,19 @@ class ConsoleApplication(BaseApplication):
return v.get()
def acquire_input(self, content=None):
def acquire_input(self, content=None, editor_params=None):
editor = os.getenv('EDITOR', 'vi')
if sys.stdin.isatty() and editor:
with NamedTemporaryFile() as f:
filename = f.name
if content is not None:
if isinstance(content, unicode):
content = content.encode(sys.stdin.encoding or locale.getpreferredencoding())
f.write(content)
f.flush()
os.system("%s %s" % (editor, filename))
if editor_params is not None and editor in editor_params:
params = editor_params[editor]
os.system("%s %s %s" % (editor, params, filename))
f.seek(0)
text = f.read()
else: