The forthcoming BCX v8.1.2 will have a revised CLS runtime that clears the scroll back buffer.
Tested on Windows 11. It seems to work as it should.
Feel free to test on other versions of Windows by swapping out the CLS runtime with this one.
void cls(void)
{
DWORD cCharsWritten;
COORD coordScreen = { 0, 0 };
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
WORD attr;
// Get current screen buffer info
GetConsoleScreenBufferInfo(hConsole, &csbi);
// Calculate the console screen size
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the console with spaces
FillConsoleOutputCharacter(hConsole, (TCHAR)' ', dwConSize, coordScreen, &cCharsWritten);
// Fill the console with the current text and background colors
attr = (WORD)color_fg + (WORD)color_bg * 16;
FillConsoleOutputAttribute(hConsole, attr, dwConSize, coordScreen, &cCharsWritten);
SMALL_RECT rect;
rect.Left = 0;
rect.Top = 0;
rect.Right = csbi.dwSize.X - 1;
rect.Bottom = csbi.dwSize.Y - 1;
// Clear the scrollback buffer by resizing the console buffer
SetConsoleWindowInfo(hConsole, TRUE, &rect);
SetConsoleScreenBufferSize(hConsole, csbi.dwSize);
locate(1, 1, 1);
}