Improve test-runner output

* fix rewind_cursor() for windows
* use stderr consistently
* let rewind_cursor() return void; closes #14
This commit is contained in:
Bert Belder 2011-05-04 00:29:57 +02:00
parent 4199a11202
commit 6d09362c8e
3 changed files with 17 additions and 7 deletions

View File

@ -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");
}

View File

@ -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");
}
}

View File

@ -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_ */