import click, sys, os, tempfile import subprocess as X import textwrap, editor chords = ['a minor', 'c major'] @click.command() def go(): # text = click.edit(click.get_text_stream('stdin', encoding='utf-8').read().strip()) # # print(type(text)) # # for lines in text.splitlines(): # # li=lines.strip() # # if not li.startswith("#"): # # click.echo(lines) # click.echo(text, nl=False) EDITOR = os.environ.get('EDITOR','vim') #that easy! initial_message = sys.stdin.buffer.read() # if you want to set up the file somehow # with tempfile.NamedTemporaryFile(suffix=".tmp") as tf: # tf.write(initial_message) # tf.flush() # call([EDITOR, tf.name]) # # do the parsing with `tf` using regular File operations. # # for instance: # tf.seek(0) # edited_message = tf.read() edited_message = editor.edit(contents=initial_message, use_tty=True) print(*chords) X.call(['stty', 'sane'], shell=True ) print(edited_message.decode('utf-8')) # print(sys.stdin.isatty())