]> granicus.if.org Git - handbrake/commitdiff
cli: Fix encoding progress line breaks on Windows.
authorBradley Sepos <bradley@bradleysepos.com>
Sat, 17 Jun 2017 19:20:55 +0000 (15:20 -0400)
committerBradley Sepos <bradley@bradleysepos.com>
Sat, 17 Jun 2017 19:39:03 +0000 (15:39 -0400)
test/test.c

index 4e35cd8c3c27fd10980fc841ce30986d900a5ed3..6c5e6e0b9af7ca786b9213fad74974b424bdcc24 100644 (file)
@@ -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);