From 11a8e301f4d8217c0f4f9f60860736d4daca8aa7 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 27 Jan 2016 20:39:00 +0100 Subject: [PATCH] Clear the screen before printing stats --- cmdline/mingw.c | 22 ++++++++++++++++++++++ cmdline/portable.h | 5 +++++ cmdline/state.c | 1 + cmdline/unix.c | 6 ++++++ 4 files changed, 34 insertions(+) diff --git a/cmdline/mingw.c b/cmdline/mingw.c index 3139772c..e15b1e3a 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -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(). */ diff --git a/cmdline/portable.h b/cmdline/portable.h index 2540d3d4..5b820410 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -352,6 +352,11 @@ void os_done(void); */ void os_abort(void) __noreturn; +/** + * Clear the screen. + */ +void os_clear(void); + /** * Log file. * diff --git a/cmdline/state.c b/cmdline/state.c index 61c940c4..57d7a9c0 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -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); } } diff --git a/cmdline/unix.c b/cmdline/unix.c index d71243b6..b6681e42 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -1226,5 +1226,11 @@ void os_abort(void) } /* LCOV_EXCL_STOP */ +void os_clear(void) +{ + /* ANSI code for clear screen */ + printf("\033[2J"); +} + #endif