Windows: Force console output to UTF-8.
This commit is contained in:
parent
de5363ee63
commit
811840740d
@ -22,7 +22,7 @@
|
||||
namespace textinput {
|
||||
TerminalDisplayWin::TerminalDisplayWin():
|
||||
TerminalDisplay(false), fStartLine(0), fIsAttached(false),
|
||||
fDefaultAttributes(0) {
|
||||
fDefaultAttributes(0), fOldCodePage(::GetConsoleOutputCP()) {
|
||||
DWORD mode;
|
||||
SetIsTTY(::GetConsoleMode(::GetStdHandle(STD_INPUT_HANDLE), &mode) != 0);
|
||||
|
||||
@ -40,7 +40,8 @@ namespace textinput {
|
||||
::GetConsoleScreenBufferInfo(fOut, &csbi);
|
||||
fDefaultAttributes = csbi.wAttributes;
|
||||
assert(fDefaultAttributes != 0 && "~TerminalDisplayWin broken");
|
||||
}
|
||||
} else
|
||||
::SetConsoleOutputCP(65001); // Force UTF-8 output
|
||||
fMyMode = fOldMode | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
||||
HandleResizeEvent();
|
||||
}
|
||||
@ -50,7 +51,8 @@ namespace textinput {
|
||||
::SetConsoleTextAttribute(fOut, fDefaultAttributes);
|
||||
// We allocated CONOUT$:
|
||||
CloseHandle(fOut);
|
||||
}
|
||||
} else
|
||||
::SetConsoleOutputCP(fOldCodePage);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -54,6 +54,7 @@ namespace textinput {
|
||||
DWORD fOldMode; // console configuration before grabbing
|
||||
DWORD fMyMode; // console configuration when active
|
||||
WORD fDefaultAttributes; // attributes to restore on destruction
|
||||
const UINT fOldCodePage; // saved codepage of console
|
||||
};
|
||||
}
|
||||
#endif // TEXTINPUT_TERMINALDISPLAYWIN_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user