diff --git a/test/runner-unix.c b/test/runner-unix.c index 32570449..c4d6d72a 100644 --- a/test/runner-unix.c +++ b/test/runner-unix.c @@ -298,7 +298,6 @@ void process_cleanup(process_info_t *p) { /* Move the console cursor one line up and back to the first column. */ -int rewind_cursor() { - printf("\033[2K\r"); - return 0; +void rewind_cursor() { + fprintf(stderr, "\033[2K\r"); } diff --git a/test/runner-win.c b/test/runner-win.c index 84726e1c..5c79675a 100644 --- a/test/runner-win.c +++ b/test/runner-win.c @@ -221,12 +221,13 @@ void process_cleanup(process_info_t *p) { } -int rewind_cursor() { +static int clear_line() { HANDLE handle; CONSOLE_SCREEN_BUFFER_INFO info; COORD coord; + DWORD written; - handle = (HANDLE)_get_osfhandle(fileno(stdout)); + handle = (HANDLE)_get_osfhandle(fileno(stderr)); if (handle == INVALID_HANDLE_VALUE) return -1; @@ -237,11 +238,21 @@ int rewind_cursor() { if (coord.Y <= 0) return -1; - coord.Y--; coord.X = 0; if (!SetConsoleCursorPosition(handle, coord)) return -1; + if (!FillConsoleOutputCharacterW(handle, 0x20, info.dwSize.X, coord, &written)) + return -1; + return 0; } + + +void rewind_cursor() { + if (clear_line() == -1) { + /* If clear_line fails (stdout is not a console), print a newline. */ + fprintf(stderr, "\n"); + } +} diff --git a/test/runner.h b/test/runner.h index a4c7fe3c..a6af951f 100644 --- a/test/runner.h +++ b/test/runner.h @@ -140,6 +140,6 @@ int process_reap(process_info_t *p); void process_cleanup(process_info_t *p); /* Move the console cursor one line up and back to the first column. */ -int rewind_cursor(); +void rewind_cursor(); #endif /* RUNNER_H_ */