diff --git a/src/nasal_err.cpp b/src/nasal_err.cpp index 35c1988..f9ba2a0 100644 --- a/src/nasal_err.cpp +++ b/src/nasal_err.cpp @@ -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; }