aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.cpp
diff options
context:
space:
mode:
authorfireice-uk <fireice-uk@users.noreply.github.com>2018-09-19 13:39:01 +0100
committerfireice-uk <fireice-uk@users.noreply.github.com>2018-09-19 13:39:01 +0100
commit579383c26b3cc8f29e09a55bc24446b9141f4f87 (patch)
tree05942baede799246fe4c46482f65b40258a815e0 /src/common/util.cpp
parentMerge pull request #4381 (diff)
downloadmonero-579383c26b3cc8f29e09a55bc24446b9141f4f87.tar.xz
simplewallet: Add Unicode input_line [Ryo backport]
Diffstat (limited to '')
-rw-r--r--src/common/util.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/common/util.cpp b/src/common/util.cpp
index c56c77505..2a1d49af0 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -939,4 +939,32 @@ std::string get_nix_version_display_string()
}
return newval;
}
+
+#ifdef _WIN32
+ std::string input_line_win()
+ {
+ HANDLE hConIn = CreateFileW(L"CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
+ DWORD oldMode;
+
+ FlushConsoleInputBuffer(hConIn);
+ GetConsoleMode(hConIn, &oldMode);
+ SetConsoleMode(hConIn, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
+
+ wchar_t buffer[1024];
+ DWORD read;
+
+ ReadConsoleW(hConIn, buffer, sizeof(buffer)/sizeof(wchar_t)-1, &read, nullptr);
+ buffer[read] = 0;
+
+ SetConsoleMode(hConIn, oldMode);
+ CloseHandle(hConIn);
+
+ int size_needed = WideCharToMultiByte(CP_UTF8, 0, buffer, -1, NULL, 0, NULL, NULL);
+ std::string buf(size_needed, '\0');
+ WideCharToMultiByte(CP_UTF8, 0, buffer, -1, &buf[0], size_needed, NULL, NULL);
+ buf.pop_back(); //size_needed includes null that we needed to have space for
+ return buf;
+ }
+#endif
+
}