Skip to content

Commit

Permalink
cli: Fix encoding progress line breaks on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleysepos committed Jun 17, 2017
1 parent a545086 commit 410d4df
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions test/test.c
Expand Up @@ -220,8 +220,38 @@ static int is_whole_media_service( io_service_t service );
static int show_mux_warning = 1; static int show_mux_warning = 1;


/* Terminal detection */ /* Terminal detection */
static char * stdout_sep = NULL; static int stdout_tty = 0;
static char * stderr_sep = NULL; 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 * hb_error_handler
Expand Down Expand Up @@ -310,7 +340,14 @@ void EventLoop(hb_handle_t *h, hb_dict_t *preset_dict)
} }
} }
#endif #endif
hb_snooze( 200 ); if (stdout_tty == 0)
{
hb_snooze(2000);
}
else
{
hb_snooze(200);
}


HandleEvents( h, preset_dict ); HandleEvents( h, preset_dict );
} }
Expand Down Expand Up @@ -390,23 +427,7 @@ int main( int argc, char ** argv )
/* Init libhb */ /* Init libhb */
h = hb_init(4); // Show all logging until debug level is parsed h = hb_init(4); // Show all logging until debug level is parsed


/* Terminal detection */ test_tty(); // 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");
}


// Get utf8 command line if windows // Get utf8 command line if windows
get_argv_utf8(&argc, &argv); get_argv_utf8(&argc, &argv);
Expand Down

0 comments on commit 410d4df

Please sign in to comment.