Move not in_pipe->list(lines) so it is inherent to multiline input.

This commit is contained in:
voussoir 2020-12-05 22:56:40 -08:00
parent 051b783964
commit 86f2186dd6

View file

@ -35,14 +35,7 @@ def ctrlc_return1(function):
return 1 return 1
return wrapped return wrapped
def multi_line_input(prompt=None): def _multi_line_input(prompt=None):
'''
Yield multiple lines of input from the user, until they submit EOF.
EOF is usually Ctrl+D on linux and Ctrl+Z on windows.
The prompt is only shown for non-pipe situations, so you do not need to
adjust your `prompt` argument for pipe/non-pipe usage.
'''
if prompt is not None and not IN_PIPE: if prompt is not None and not IN_PIPE:
sys.stderr.write(prompt) sys.stderr.write(prompt)
sys.stderr.flush() sys.stderr.flush()
@ -67,6 +60,23 @@ def multi_line_input(prompt=None):
if has_eof: if has_eof:
break break
def multi_line_input(prompt=None):
'''
Yield multiple lines of input from the user, until they submit EOF.
EOF is usually Ctrl+D on linux and Ctrl+Z on windows.
The prompt is only shown for non-pipe situations, so you do not need to
adjust your `prompt` argument for pipe/non-pipe usage.
'''
lines = _multi_line_input(prompt=prompt)
if not IN_PIPE:
# Wait until the user finishes all their lines before continuing.
# The caller might be processing + printing these lines in a loop
# and it would be weird if they start outputting before the user has
# finished inputting.
lines = list(lines)
return lines
def input( def input(
arg, arg,
*, *,
@ -79,12 +89,6 @@ def input(
if arg_lower in INPUT_STRINGS: if arg_lower in INPUT_STRINGS:
lines = multi_line_input(prompt=input_prompt) lines = multi_line_input(prompt=input_prompt)
if not IN_PIPE:
# Wait until the user finishes all their lines before continuing.
# The caller might be processing + printing these lines in a loop
# and it would be weird if they start outputting before the user has
# finished inputting.
lines = list(lines)
elif arg_lower in CLIPBOARD_STRINGS: elif arg_lower in CLIPBOARD_STRINGS:
import pyperclip import pyperclip