Skip to content

Commit

Permalink
[vcpkg] use UTF-8 for console input/output
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixaill authored and alexkaratarakis committed Aug 26, 2017
1 parent 98ee8a9 commit af01792
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@

using namespace vcpkg;

UINT console_cp_input;
UINT console_cp_output;

void console_cp_set()
{
console_cp_input = GetConsoleCP();
console_cp_output = GetConsoleOutputCP();

SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
}

void console_cp_reset()
{
SetConsoleCP(console_cp_input);
SetConsoleOutputCP(console_cp_output);
}

BOOL console_ctrl_handler(DWORD fdwCtrlType)
{
console_cp_reset();
return TRUE;
}

void invalid_command(const std::string& cmd)
{
System::println(System::Color::error, "invalid command: %s", cmd);
Expand Down Expand Up @@ -192,6 +216,10 @@ int wmain(const int argc, const wchar_t* const* const argv)
{
if (argc == 0) std::abort();

console_cp_set();
SetConsoleCtrlHandler(PHANDLER_ROUTINE(console_ctrl_handler), TRUE);
atexit(console_cp_reset);

*GlobalState::timer.lock() = ElapsedTime::create_started();

// Checks::register_console_ctrl_handler();
Expand Down

0 comments on commit af01792

Please sign in to comment.