mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-03-13 16:38:53 +01:00
Ported: Expose OS.read_string_from_stdin() to the scripting API
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`.
- Calinou
badcfa2523
This commit is contained in:
parent
30d7a3c5a7
commit
79842beb9a
@ -484,6 +484,10 @@ Error _OS::shell_open(String p_uri) {
|
|||||||
return OS::get_singleton()->shell_open(p_uri);
|
return OS::get_singleton()->shell_open(p_uri);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
String _OS::read_string_from_stdin() {
|
||||||
|
return OS::get_singleton()->get_stdin_string();
|
||||||
|
}
|
||||||
|
|
||||||
int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr, bool p_open_console) {
|
int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr, bool p_open_console) {
|
||||||
OS::ProcessID pid = -2;
|
OS::ProcessID pid = -2;
|
||||||
int exitcode = 0;
|
int exitcode = 0;
|
||||||
@ -1367,6 +1371,7 @@ void _OS::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("get_processor_name"), &_OS::get_processor_name);
|
ClassDB::bind_method(D_METHOD("get_processor_name"), &_OS::get_processor_name);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_executable_path"), &_OS::get_executable_path);
|
ClassDB::bind_method(D_METHOD("get_executable_path"), &_OS::get_executable_path);
|
||||||
|
ClassDB::bind_method(D_METHOD("read_string_from_stdin"), &_OS::read_string_from_stdin);
|
||||||
ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "blocking", "output", "read_stderr", "open_console"), &_OS::execute, DEFVAL(true), DEFVAL(Array()), DEFVAL(false), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "blocking", "output", "read_stderr", "open_console"), &_OS::execute, DEFVAL(true), DEFVAL(Array()), DEFVAL(false), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("kill", "pid"), &_OS::kill);
|
ClassDB::bind_method(D_METHOD("kill", "pid"), &_OS::kill);
|
||||||
ClassDB::bind_method(D_METHOD("shell_open", "uri"), &_OS::shell_open);
|
ClassDB::bind_method(D_METHOD("shell_open", "uri"), &_OS::shell_open);
|
||||||
|
@ -242,6 +242,7 @@ public:
|
|||||||
int get_low_processor_usage_mode_sleep_usec() const;
|
int get_low_processor_usage_mode_sleep_usec() const;
|
||||||
|
|
||||||
String get_executable_path() const;
|
String get_executable_path() const;
|
||||||
|
String read_string_from_stdin();
|
||||||
int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking = true, Array p_output = Array(), bool p_read_stderr = false, bool p_open_console = false);
|
int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking = true, Array p_output = Array(), bool p_read_stderr = false, bool p_open_console = false);
|
||||||
|
|
||||||
Error kill(int p_pid);
|
Error kill(int p_pid);
|
||||||
|
@ -157,7 +157,7 @@ public:
|
|||||||
void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
void printerr(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
|
||||||
|
|
||||||
virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0;
|
virtual void alert(const String &p_alert, const String &p_title = "ALERT!") = 0;
|
||||||
virtual String get_stdin_string(bool p_block = true) = 0;
|
virtual String get_stdin_string() = 0;
|
||||||
|
|
||||||
enum MouseMode {
|
enum MouseMode {
|
||||||
MOUSE_MODE_VISIBLE,
|
MOUSE_MODE_VISIBLE,
|
||||||
|
@ -891,6 +891,13 @@
|
|||||||
Shows all resources currently used by the game.
|
Shows all resources currently used by the game.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="read_string_from_stdin">
|
||||||
|
<return type="String" />
|
||||||
|
<description>
|
||||||
|
Reads a user input string from the standard input (usually the terminal). This operation is [i]blocking[/i], which causes the window to freeze if [method read_string_from_stdin] is called on the main thread. The thread calling [method read_string_from_stdin] will block until the program receives a line break in standard input (usually by the user pressing [kbd]Enter[/kbd]).
|
||||||
|
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="request_attention">
|
<method name="request_attention">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<description>
|
<description>
|
||||||
|
@ -136,15 +136,11 @@ void OS_Unix::alert(const String &p_alert, const String &p_title) {
|
|||||||
fprintf(stderr, "ALERT: %s: %s\n", p_title.utf8().get_data(), p_alert.utf8().get_data());
|
fprintf(stderr, "ALERT: %s: %s\n", p_title.utf8().get_data(), p_alert.utf8().get_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
String OS_Unix::get_stdin_string(bool p_block) {
|
String OS_Unix::get_stdin_string() {
|
||||||
if (p_block) {
|
|
||||||
char buff[1024];
|
char buff[1024];
|
||||||
String ret = stdin_buf + fgets(buff, 1024, stdin);
|
String ret = stdin_buf + fgets(buff, 1024, stdin);
|
||||||
stdin_buf = "";
|
stdin_buf = "";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String OS_Unix::get_name() const {
|
String OS_Unix::get_name() const {
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
OS_Unix();
|
OS_Unix();
|
||||||
|
|
||||||
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
|
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
|
||||||
virtual String get_stdin_string(bool p_block);
|
virtual String get_stdin_string();
|
||||||
|
|
||||||
//virtual void set_mouse_show(bool p_show);
|
//virtual void set_mouse_show(bool p_show);
|
||||||
//virtual void set_mouse_grab(bool p_grab);
|
//virtual void set_mouse_grab(bool p_grab);
|
||||||
|
@ -3165,12 +3165,8 @@ bool OS_Windows::set_environment(const String &p_var, const String &p_value) con
|
|||||||
}
|
}
|
||||||
|
|
||||||
String OS_Windows::get_stdin_string(bool p_block) {
|
String OS_Windows::get_stdin_string(bool p_block) {
|
||||||
if (p_block) {
|
|
||||||
char buff[1024];
|
char buff[1024];
|
||||||
return fgets(buff, 1024, stdin);
|
return fgets(buff, 1024, stdin);
|
||||||
};
|
|
||||||
|
|
||||||
return String();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_Windows::enable_for_stealing_focus(ProcessID pid) {
|
void OS_Windows::enable_for_stealing_focus(ProcessID pid) {
|
||||||
|
@ -433,7 +433,7 @@ public:
|
|||||||
LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
|
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
|
||||||
String get_stdin_string(bool p_block);
|
String get_stdin_string();
|
||||||
|
|
||||||
void set_mouse_mode(MouseMode p_mode);
|
void set_mouse_mode(MouseMode p_mode);
|
||||||
MouseMode get_mouse_mode() const;
|
MouseMode get_mouse_mode() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user