Ported from godot4: Fix reading Unicode from stdio.

- bruvzg
3d8a942a56
This commit is contained in:
Relintai 2023-08-05 20:33:48 +02:00
parent c4e76950fa
commit 4bb48a4a5c
3 changed files with 6 additions and 7 deletions

View File

@ -138,9 +138,7 @@ void OS_Unix::alert(const String &p_alert, const String &p_title) {
String OS_Unix::get_stdin_string() { String OS_Unix::get_stdin_string() {
char buff[1024]; char buff[1024];
String ret = stdin_buf + fgets(buff, 1024, stdin); return String::utf8(fgets(buff, 1024, stdin));
stdin_buf = "";
return ret;
} }
String OS_Unix::get_name() const { String OS_Unix::get_name() const {

View File

@ -46,8 +46,6 @@ protected:
virtual void finalize_core(); virtual void finalize_core();
String stdin_buf;
public: public:
OS_Unix(); OS_Unix();

View File

@ -3166,8 +3166,11 @@ bool OS_Windows::set_environment(const String &p_var, const String &p_value) con
} }
String OS_Windows::get_stdin_string() { String OS_Windows::get_stdin_string() {
char buff[1024]; WCHAR buff[1024];
return fgets(buff, 1024, stdin); DWORD count = 0;
if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), buff, 1024, &count, nullptr)) {
return String::utf16((const char16_t *)buff, count);
}
} }
void OS_Windows::enable_for_stealing_focus(ProcessID pid) { void OS_Windows::enable_for_stealing_focus(ProcessID pid) {