diff options
author | Bradley Sepos <[email protected]> | 2017-06-17 15:20:55 -0400 |
---|---|---|
committer | Bradley Sepos <[email protected]> | 2017-06-17 15:39:03 -0400 |
commit | 410d4dff815f14418cae7700d901c1bf2223ba77 (patch) | |
tree | b15eda1d33adbbf2d0f7be35e1f59c2ce0437e04 /test | |
parent | a54508601b429938212fc9bfd0db7d5d68ac5e01 (diff) |
cli: Fix encoding progress line breaks on Windows.
Diffstat (limited to 'test')
-rw-r--r-- | test/test.c | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/test/test.c b/test/test.c index 4e35cd8c3..6c5e6e0b9 100644 --- a/test/test.c +++ b/test/test.c @@ -220,8 +220,38 @@ static int is_whole_media_service( io_service_t service ); static int show_mux_warning = 1; /* Terminal detection */ -static char * stdout_sep = NULL; -static char * stderr_sep = NULL; +static int stdout_tty = 0; +static int stderr_tty = 0; +static char * stdout_sep = "\n"; +static char * stderr_sep = "\n"; +static void test_tty() +{ +#if defined(__MINGW32__) + HANDLE handle; + handle = (HANDLE) _get_osfhandle(_fileno(stdout)); + if ((handle != INVALID_HANDLE_VALUE) && (GetFileType(handle) == FILE_TYPE_CHAR)) + { + stdout_tty = 1; + } + handle = (HANDLE) _get_osfhandle(_fileno(stderr)); + if ((handle != INVALID_HANDLE_VALUE) && (GetFileType(handle) == FILE_TYPE_CHAR)) + { + stderr_tty = 1; + } +#else + if (isatty(1) == 1) + { + stdout_tty = 1; + } + if (isatty(2) == 1) + { + stderr_tty = 1; + } +#endif + + if (stdout_tty == 1) stdout_sep = "\r"; + if (stdout_tty == 1) stderr_sep = "\r"; +} /**************************************************************************** * hb_error_handler @@ -310,7 +340,14 @@ void EventLoop(hb_handle_t *h, hb_dict_t *preset_dict) } } #endif - hb_snooze( 200 ); + if (stdout_tty == 0) + { + hb_snooze(2000); + } + else + { + hb_snooze(200); + } HandleEvents( h, preset_dict ); } @@ -390,23 +427,7 @@ int main( int argc, char ** argv ) /* Init libhb */ h = hb_init(4); // Show all logging until debug level is parsed - /* Terminal detection */ - if (isatty(1) == 1) - { - stdout_sep = strdup("\r"); - } - else - { - stdout_sep = strdup("\n"); - } - if (isatty(2) == 1) - { - stderr_sep = strdup("\r"); - } - else - { - stderr_sep = strdup("\n"); - } + test_tty(); // Terminal detection // Get utf8 command line if windows get_argv_utf8(&argc, &argv); |