#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>
int main()
{
int i;
struct winsize w;
char *spaces;
/* Get terminal window size: */
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
/* Allocate enough spaces to fill the whole
* whole window (rows * cols):*/
spaces = (char *)malloc(w.ws_row * w.ws_col);
memset(spaces, ' ', w.ws_row * w.ws_col);
/* Change background color, then print
* rows * cols of white spaces: */
for(i = 0; 1; i++) {
printf("\e[7;%dm\n", 31 + i%6);
write(1, spaces, w.ws_row * w.ws_col);
usleep(1000 * 1000);
}
return 0;
}