Clear the screen before printing stats

This commit is contained in:
Andrea Mazzoleni 2016-01-27 20:39:00 +01:00
parent 252d613eae
commit 11a8e301f4
4 changed files with 34 additions and 0 deletions

View file

@ -271,6 +271,28 @@ void os_abort(void)
exit(EXIT_FAILURE);
}
void os_clear(void)
{
HANDLE console;
CONSOLE_SCREEN_BUFFER_INFO screen;
COORD coord;
DWORD written;
/* get the console */
console = GetStdHandle(STD_OUTPUT_HANDLE);
if (console == INVALID_HANDLE_VALUE)
return;
/* get the screen size */
if (!GetConsoleScreenBufferInfo(console, &screen))
return;
/* fill the screen with spaces */
coord.X = 0;
coord.Y = 0;
FillConsoleOutputCharacterA(console, ' ', screen.dwSize.X * screen.dwSize.Y, coord, &written);
}
/**
* Size in chars of conversion buffers for u8to16() and u16to8().
*/

View file

@ -352,6 +352,11 @@ void os_done(void);
*/
void os_abort(void) __noreturn;
/**
* Clear the screen.
*/
void os_clear(void);
/**
* Log file.
*

View file

@ -4018,6 +4018,7 @@ int state_progress(struct snapraid_state* state, struct snapraid_io* io, block_o
out_eta = (countmax - countpos) * delta_time / (60 * delta_pos);
if (msg_level >= MSG_VERBOSE) {
os_clear();
state_usage_graph(state, io, state->progress_ptr, oldest);
}
}

View file

@ -1226,5 +1226,11 @@ void os_abort(void)
}
/* LCOV_EXCL_STOP */
void os_clear(void)
{
/* ANSI code for clear screen */
printf("\033[2J");
}
#endif