#include <windows.h>
void ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}
Unix Systems :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <unistd.h>
#include <term.h>
void ClearScreen()
{
if (!cur_term)
{
int result;
setupterm( NULL, STDOUT_FILENO, &result );
if (result <= 0) return;
}
putp( tigetstr( "clear" ) );
}
Thank Duoas not me, and thank you for using a question mark and using english but why did you post this in the article section?
There is no solution on the C/C++ side except to reduce the amount of output to the terminal in some way. The problem is with your terminal emulator. (If you are on Windows, I empathize. If you are on Linux, there are some fast terminal emulators out there. Eschew those with fancy add-ons.)
The terminal... slow? I thought it only held a certain amount of text, and then it began to clear lines from the top? At least, that's what happens for me.
X is designed so that very little information needs to be sent back and forth between server and client. All the fancy GUI drawing stuff is on the terminal. For home systems (Linux, etc), the server and client reside on the same host, so it isn't a real big problem.
The problem is the stupid terminal emulator, which is trying to do too much fancy stuff to render simple text.