diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-09-13 18:37:11 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-09-13 18:37:11 +0200 |
commit | 8b5bb7eeeaf666dc7bb390a16599c6674d34a8ed (patch) | |
tree | b54125263c31ee4e72ee8bdf858c23419b6f9bc3 | |
parent | f6b36f54e50cff518b4085cf665405ad1b5f6d44 (diff) | |
download | redot-engine-8b5bb7eeeaf666dc7bb390a16599c6674d34a8ed.tar.gz |
[OS] Expose get_stdin_string to Scripting.
Exposed as read_string_from_stdin so it's clear it's not retrieving a
property.
The method is kept with the block parameter, but a note is added to the
docs specifying that is not implemented on any platform (should we just
remove it?).
-rw-r--r-- | core/core_bind.cpp | 5 | ||||
-rw-r--r-- | core/core_bind.h | 1 | ||||
-rw-r--r-- | doc/classes/OS.xml | 8 |
3 files changed, 14 insertions, 0 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 9daf58cb71..91fc4489f7 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -253,6 +253,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); +} + int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr, bool p_open_console) { List<String> args; for (int i = 0; i < p_arguments.size(); i++) { @@ -522,6 +526,7 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_system_fonts"), &OS::get_system_fonts); ClassDB::bind_method(D_METHOD("get_system_font_path", "font_name", "bold", "italic"), &OS::get_system_font_path, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path); + ClassDB::bind_method(D_METHOD("read_string_from_stdin", "block"), &OS::read_string_from_stdin, DEFVAL(true)); ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL(Array()), DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false)); ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance); diff --git a/core/core_bind.h b/core/core_bind.h index cd382d2915..c0fbdcae86 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -175,6 +175,7 @@ public: Vector<String> get_system_fonts() const; String get_system_font_path(const String &p_font_name, bool p_bold = false, bool p_italic = false) const; String get_executable_path() const; + String read_string_from_stdin(bool p_block = true); int execute(const String &p_path, const Vector<String> &p_arguments, Array r_output = Array(), bool p_read_stderr = false, bool p_open_console = false); int create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console = false); int create_instance(const Vector<String> &p_arguments); diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 059766656f..56fd4ade47 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -517,6 +517,14 @@ [b]Note:[/b] This method is implemented on Linux, macOS and Windows. </description> </method> + <method name="read_string_from_stdin"> + <return type="String" /> + <param index="0" name="block" type="bool" default="true" /> + <description> + Reads a user input string from the standard input (usually the terminal). + [b]Note:[/b] This method is implemented on Linux, macOS and Windows. Non-blocking reads are not currently supported on any platform. + </description> + </method> <method name="request_permission"> <return type="bool" /> <param index="0" name="name" type="String" /> |