diff mbox series

[FFmpeg-devel,2/5] avutil/log: factorize ansi_fputs

Message ID 20200202211534.12739-2-cus@passwd.hu
State Accepted
Headers show
Series [FFmpeg-devel,1/5] avutil/log: drop support for NO_COLOR environment variable | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Marton Balint Feb. 2, 2020, 9:15 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavutil/log.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

Comments

Michael Niedermayer Feb. 3, 2020, 10 a.m. UTC | #1
On Sun, Feb 02, 2020 at 10:15:31PM +0100, Marton Balint wrote:
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavutil/log.c | 41 +++++++++++++++++++++++------------------
>  1 file changed, 23 insertions(+), 18 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libavutil/log.c b/libavutil/log.c
index 6d87c718a8..64950016e8 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -143,25 +143,8 @@  static void check_color_terminal(void)
 #endif
 }
 
-static void colored_fputs(int level, int tint, const char *str)
+static void ansi_fputs(int level, int tint, const char *str, int local_use_color)
 {
-    int local_use_color;
-    if (!*str)
-        return;
-
-    if (use_color < 0)
-        check_color_terminal();
-
-    if (level == AV_LOG_INFO/8) local_use_color = 0;
-    else                        local_use_color = use_color;
-
-#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
-    if (local_use_color)
-        SetConsoleTextAttribute(con, background | color[level]);
-    fputs(str, stderr);
-    if (local_use_color)
-        SetConsoleTextAttribute(con, attr_orig);
-#else
     if (local_use_color == 1) {
         fprintf(stderr,
                 "\033[%"PRIu32";3%"PRIu32"m%s\033[0m",
@@ -182,6 +165,28 @@  static void colored_fputs(int level, int tint, const char *str)
                 str);
     } else
         fputs(str, stderr);
+}
+
+static void colored_fputs(int level, int tint, const char *str)
+{
+    int local_use_color;
+    if (!*str)
+        return;
+
+    if (use_color < 0)
+        check_color_terminal();
+
+    if (level == AV_LOG_INFO/8) local_use_color = 0;
+    else                        local_use_color = use_color;
+
+#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
+    if (local_use_color)
+        SetConsoleTextAttribute(con, background | color[level]);
+    fputs(str, stderr);
+    if (local_use_color)
+        SetConsoleTextAttribute(con, attr_orig);
+#else
+    ansi_fputs(level, tint, str, local_use_color);
 #endif
 
 }