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

Console.readAll blocks until EOF #20

Closed
mhonert opened this issue Feb 9, 2020 · 6 comments
Closed

Console.readAll blocks until EOF #20

mhonert opened this issue Feb 9, 2020 · 6 comments

Comments

@mhonert
Copy link
Contributor

mhonert commented Feb 9, 2020

The Console.readAll function blocks until the EOF character is entered (e.g. by pressing CTRL-D in a linux shell), so it is not that useful for a CLI application.

It would be great if there was a function which reads a whole line until a newline character is entered (e.g. Console.readLine).

For portability this should probably take different newline character sequences into account (e.g. CR+LF for Windows and only LF for Linux/macOS).

@jedisct1
Copy link
Owner

jedisct1 commented Feb 9, 2020

I'm not sure how to do that. WASI doesn't expose anything about the underlying environment, so we don't know what an end of line looks like.

@MaxGraey
Copy link
Contributor

MaxGraey commented Feb 9, 2020

I guess it relate to this discussion: WebAssembly/WASI#162

@mhonert
Copy link
Contributor Author

mhonert commented Feb 10, 2020

If we can assume that a newline always ends with LF regardless of the platform, then
a simple solution would perhaps be to skip any CR characters?
At least this is how I implemented it for now in my chess engine, which reads UCI protocol commands from STDIN.

But I do not know, whether there are any use cases where recognizing the CR character might be necessary.

@mhonert
Copy link
Contributor Author

mhonert commented Feb 21, 2020

I had a look at the ReadLine implementation of Go and they simply skip the CR (\r) character as well, if it is followed by a LF (\n): bufio.go.

@jedisct1
Copy link
Owner

But then, we have a similar problem with the WriteLine() counterpart.

@mhonert
Copy link
Contributor Author

mhonert commented Feb 22, 2020

It seems that Go always writes '\n', regardless of the platform. For console output this is probably fine, although I did not yet check what happens when stdout is redirected to a file in Windows.

@jedisct1 jedisct1 closed this as completed Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants