]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala, libvaladoc: Fix color support detection in log reporting
authorZhou Qiankang <wszqkzqk@qq.com>
Thu, 25 Apr 2024 09:45:47 +0000 (17:45 +0800)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 29 May 2024 08:35:35 +0000 (10:35 +0200)
Use `GLib.Log.writer_supports_color` to replace vala's implementation `is_atty`

libvaladoc/errorreporter.vala
vala/valareport.vala

index d63ed6ecdb3985ac84d913a4bb492f4e6e01bea5..00950460216369ac86dc0c73e2f639f1b41418ff 100644 (file)
@@ -194,7 +194,7 @@ public class Valadoc.ErrorReporter : Object {
                        }
                }
 
-               if (is_atty (this.stream.fileno ())) {
+               if (Log.writer_supports_color (this.stream.fileno ())) {
                        if (error_color != null) {
                                this.error_color_start = "\x1b[0" + error_color + "m";
                                this.error_color_end = ANSI_COLOR_END;
@@ -228,28 +228,6 @@ public class Valadoc.ErrorReporter : Object {
                return true;
        }
 
-       [CCode (has_target = false)]
-       private delegate int AttyFunc (int fd);
-
-       private bool is_atty (int fd) {
-               Module module = Module.open (null, ModuleFlags.LAZY);
-               if (module == null) {
-                       return false;
-               }
-
-               void* _func;
-               module.symbol ("isatty", out _func);
-               if (_func == null) {
-                       module.symbol ("_isatty", out _func);
-                       if (_func == null) {
-                               return false;
-                       }
-               }
-
-               AttyFunc? func = (AttyFunc) _func;
-               return func (fd) > 0;
-       }
-
        [PrintfFormat]
        private inline void msg (string type, string type_color_start, string type_color_end, string file, long line, long startpos, long endpos,
                                                         string errline, string msg_format, va_list args)
index 5e4885a6ec2b456517f368410b21ddd1544355da..d867e5eec9a01fe5f1d45d582816a54ecb0f8709 100644 (file)
@@ -173,7 +173,7 @@ public class Vala.Report {
                        }
                }
 
-               if (colored_output == Report.Colored.ALWAYS || (colored_output == Report.Colored.AUTO && is_atty (stderr.fileno ()))) {
+               if (colored_output == Report.Colored.ALWAYS || (colored_output == Report.Colored.AUTO && Log.writer_supports_color (stderr.fileno ()))) {
                        if (error_color != null) {
                                this.error_color_start = "\x1b[0" + error_color + "m";
                                this.error_color_end = ANSI_COLOR_END;
@@ -399,27 +399,4 @@ public class Vala.Report {
        public static void error (SourceReference? source, string msg_format, ...) {
                CodeContext.get ().report.err (source, msg_format.vprintf (va_list ()));
        }
-
-
-       [CCode (has_target = false)]
-       private delegate int AttyFunc (int fd);
-
-       private bool is_atty (int fd) {
-               Module module = Module.open (null, ModuleFlags.LAZY);
-               if (module == null) {
-                       return false;
-               }
-
-               void* _func;
-               module.symbol ("isatty", out _func);
-               if (_func == null) {
-                       module.symbol ("_isatty", out _func);
-                       if (_func == null) {
-                               return false;
-                       }
-               }
-
-               AttyFunc? func = (AttyFunc) _func;
-               return func (fd) > 0;
-       }
 }