fix clear_screen on _WIN32

This commit is contained in:
ValKmjolnir 2024-08-02 22:41:03 +08:00
parent 8d3f752429
commit 21911f21f0
1 changed files with 32 additions and 1 deletions

View File

@ -15,8 +15,39 @@ static for_reset windows_system_set;
#endif
std::ostream& clear_screen(std::ostream& s) {
// TODO: winapi clear screen
#ifdef _WIN32
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE) {
return s;
}
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
return s;
}
auto rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
auto cols = csbi.srWindow.Right - csbi.srWindow.Left + 1;
DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
COORD coord = { 0, 0 };
DWORD dwCharsWritten;
FillConsoleOutputCharacter(hConsole, ' ', dwConSize, coord, &dwCharsWritten);
// set raw attribute
FillConsoleOutputAttribute(
hConsole,
csbi.wAttributes,
dwConSize,
coord,
&dwCharsWritten
);
// set cursor position
SetConsoleCursorPosition(hConsole, coord);
#else
s << "\033c";
#endif
return s;
}