Improve test-runner output
* fix rewind_cursor() for windows * use stderr consistently * let rewind_cursor() return void; closes #14
This commit is contained in:
parent
4199a11202
commit
6d09362c8e
@ -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");
|
||||
}
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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_ */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user