You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I love that Deno has built-in prompt() and confirm() 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 and false, 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:
$ rev
This is a line I typed.
.depyt I enil a si sihT
This is another line I typed.
.depyt I enil rehtona si sihT
$
It is most useful when used in a pipeline, like so:
$ fortune -l | rev
,slevel neves no tliub saw ti taht hcus saw htiriT saniM fo noihsaf eht roF
llaw hcae ni dna ,llaw a tes saw hcae tuoba dna ,llih a otni devled hcae
.etag a saw
"gniK eht fo nruteR ehT" ,neikloT .R.R.J --
nehw ,4.4V ,"serutcurtS ataD dna slanretnI SMV" ni detouQ[
].weivrevo metsys ot gnirrefer
$
One can trivially implement a rev clone in Deno by putting the following in an executable script named rev:
#!/usr/bin/env -S deno run --ext ts --check
letread;while((read=prompt(""))!=null)console.log([...read].reverse().join(""));
However, although the first use case works, the second exits immediately when prompt() returns null:
$ ./rev
This is a line I typed.
.depyt I enil a si sihT
This is another line I typed.
.depyt I enil rehtona si sihT
$ fortune -l | ./rev
$
The current behavior is achieved by the stdin.isTerminal() checks in runtime/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:
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: