mirror of
https://github.com/monero-project/monero.git
synced 2025-06-21 08:04:11 -04:00
simplewallet: Add Unicode input_line [Ryo backport]
This commit is contained in:
parent
bb30a72367
commit
579383c26b
3 changed files with 34 additions and 47 deletions
|
@ -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
|
||||
|
||||
}
|
||||
|
|
|
@ -235,4 +235,7 @@ namespace tools
|
|||
boost::optional<std::pair<uint32_t, uint32_t>> parse_subaddress_lookahead(const std::string& str);
|
||||
|
||||
std::string glob_to_regex(const std::string &val);
|
||||
#ifdef _WIN32
|
||||
std::string input_line_win();
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue