-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow prompt()
and confirm()
to read from redirected stdin
#22955
Comments
If you want to collect input from a user or machine, I suggest you call |
I acknowledge that this would be a breaking change, but it would significantly ease Deno's use as a scripting language. Given that Deno 2 is getting closer, isn't now the right time to consider breaking changes? |
Furthermore, https://deno.com/blog/v2.0-release-candidate lists the |
@lucacasonato Is there room to consider breaking I/O changes such as this before Deno 2 is final? Together with #22956 and #22957, this minor improvement to the behavior of these functions would make writing simple command-line tools in Deno seamless. |
Just the type interface is going away - not the actual method |
I love that Deno has built-in
prompt()
andconfirm()
functions because they make it easy to write command-line programs. Deno scripts make excellent replacements for Bourne shell scripts in many cases (and make things such as JSON processing trivial!).However, the input functions' response to input redirection and piping hinders non-interactive use of command-line utilities. Although they have long returned
null
andfalse
, respectively, I think the functions should instead retain their normal behavior regardless of whether the input is from a terminal.As a simple example, the standard Unix utility
rev
lets one reverse strings from standard input:It is most useful when used in a pipeline, like so:
One can trivially implement a
rev
clone in Deno by putting the following in an executable script namedrev
:However, although the first use case works, the second exits immediately when
prompt()
returnsnull
:The current behavior is achieved by the
stdin.isTerminal()
checks inruntime/js/41_prompt.js
. They have been present since the input functions were introduced, having been added in response to a reviewer feedback in #7507 with no further discussion. I think that supporting this style of command-line utility is more important than matching browser behavior in this case.I suspect that removing this special case would obviate other issues such as #22633.
The text was updated successfully, but these errors were encountered: