Skip to content
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

Closing stdin causes prompt() to output a newline, in contrast to confirm() #22956

Open
solb opened this issue Mar 16, 2024 · 0 comments
Open
Labels
bug Something isn't working correctly good first issue Good for newcomers runtime Relates to code in the runtime crate

Comments

@solb
Copy link
Contributor

solb commented Mar 16, 2024

Running the following command and pressing Ctrl+D to close the standard input stream reveals that the built-in prompt() function outputs a newline in this case:

$ deno eval 'prompt()'
Prompt
$

Surprisingly, confirm() does not exhibit this behavior (note the location of the second $ prompt):

$ deno eval 'confirm()'
Confirm [y/N] $

I would argue that the latter response is more correct, by analogy with C. Consider the following POSIX.1-2008–compliant program:

#define _DEFAULT_SOURCE
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	fputs("Prompt ", stdout);

	char *buf = NULL;
	size_t len = 0;
	getline(&buf, &len, stdin);
	free(buf);

	return 0;
}

Hitting Ctrl+D elicits the confirm()-style behavior on my GNU/Linux system:

$ c99 -o getline getline.c && ./getline
Prompt $

I noticed this inconsistency when filing #22955: it is responsible for the extra newline in the final command-line example in that issue. I haven't traced the issue deeper than prompt()'s use of op_read_line_prompt() (in contrast to confirm()'s readLineFromStdinSync()) in runtime/js/41_prompt.js.

Tested on this official release build:

$ deno --version
deno 1.41.0 (release, x86_64-unknown-linux-gnu)
v8 12.1.285.27
typescript 5.3.3
@lucacasonato lucacasonato added bug Something isn't working correctly good first issue Good for newcomers runtime Relates to code in the runtime crate labels Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly good first issue Good for newcomers runtime Relates to code in the runtime crate
Projects
None yet
Development

No branches or pull requests

2 participants