-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Expose OS.read_string_from_stdin()
to the scripting API (3.x)
#70378
Expose OS.read_string_from_stdin()
to the scripting API (3.x)
#70378
Conversation
core/bind/core_bind.cpp
Outdated
@@ -520,6 +520,10 @@ Error _OS::shell_open(String p_uri) { | |||
return OS::get_singleton()->shell_open(p_uri); | |||
}; | |||
|
|||
String _OS::read_string_from_stdin(bool p_block) { | |||
return OS::get_singleton()->get_stdin_string(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return OS::get_singleton()->get_stdin_string(true); | |
return OS::get_singleton()->get_stdin_string(p_block); |
But probably the argument should be removed at all (from both CoreBind and OS), it's not useful, setting it to false
always return empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument was likely kept in #65751 for forward compatibility (in case non-blocking stdin reading is implemented), but it's not likely to happen in 3.x
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the argument should be removed here and for 4.0 too. If it's not implemented, there's no point having it. It can be added later if we do implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also remove the unused parameter from the OS method, not just the binding.
b835626
to
422818d
Compare
OS.read_string_from_stdin()
to the scripting APIOS.read_string_from_stdin()
to the scripting API (3.x)
c8beeb6
to
cf603aa
Compare
I guess we can call read in a loop and add to
Also, will need #70389 backported for Unicode support. |
cf603aa
to
0c405b9
Compare
This can be used in scripts to read user input in a blocking manner. This also removes the unused `block` argument, which is always `true`.
7ed1a59
to
badcfa2
Compare
Thanks! |
I've tested this locally and it appears to freeze after entering a long string. The current behavior is that calling Testing project: test_long_stdin.zip |
3.x
version of #65751. See godotengine/godot-proposals#2322.This can be used in scripts to read user input in a blocking manner.
This also removes the unused
block
argument, which is alwaystrue
.Note that non-ASCII input doesn't appear to be handled correctly (tested on Linux):
In
master
, this occurs instead:Maybe @bruvzg knows about resolving this encoding issue?