From: Zhou Qiankang Date: Thu, 25 Apr 2024 09:45:47 +0000 (+0800) Subject: vala, libvaladoc: Fix color support detection in log reporting X-Git-Tag: 0.56.18~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5d690fe0a694f8039a08c0ab6ce9e6776598732;p=thirdparty%2Fvala.git vala, libvaladoc: Fix color support detection in log reporting Use `GLib.Log.writer_supports_color` to replace vala's implementation `is_atty` --- diff --git a/libvaladoc/errorreporter.vala b/libvaladoc/errorreporter.vala index d63ed6ecd..009504602 100644 --- a/libvaladoc/errorreporter.vala +++ b/libvaladoc/errorreporter.vala @@ -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) diff --git a/vala/valareport.vala b/vala/valareport.vala index 5e4885a6e..d867e5eec 100644 --- a/vala/valareport.vala +++ b/vala/valareport.vala @@ -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; - } }