From: JCWasmx86 Date: Sun, 5 Jun 2022 13:57:57 +0000 (+0200) Subject: Added colorful output X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1eebe90fd934001e143736fe11d033213073a2cc;p=thirdparty%2Fvala.git Added colorful output --- diff --git a/dbusgen/valadbusgen.vala b/dbusgen/valadbusgen.vala index 5daa100bd..ec563442a 100644 --- a/dbusgen/valadbusgen.vala +++ b/dbusgen/valadbusgen.vala @@ -25,7 +25,7 @@ using GLib; public class Vala.DBusGen { - // TODO: Colored output + public class ConcatenationStrategy : NamespaceStrategy { public override string? get_namespace (string ns) { @@ -63,6 +63,8 @@ public class Vala.DBusGen { static string[] rename_namespaces; [CCode (array_length = false, array_null_terminated = true)] static string[] strip_namespaces; + static bool disable_colored_output; + static Report.Colored colored_output = Report.Colored.AUTO; CodeContext context; @@ -75,11 +77,14 @@ public class Vala.DBusGen { { "rename-namespace", 0, 0, OptionArg.STRING_ARRAY, ref rename_namespaces, "Namespace to rename to", "SOURCE_NS:TARGET_NS..." }, { "strip-namespace", 0, 0, OptionArg.STRING_ARRAY, ref strip_namespaces, "Namespace to strip", "NAMESPACE..." }, { "dbus-timeout", 0, 0, OptionArg.INT, ref dbus_timeout, "DBus timeout", null }, + { "no-color", 0, 0, OptionArg.NONE, ref disable_colored_output, "Disable colored output, alias for --color=never", null }, + { "color", 0, OptionFlags.OPTIONAL_ARG, OptionArg.CALLBACK, (void*) option_parse_color, "Enable color output, options are 'always', 'never', or 'auto'", "WHEN" }, { "version", 0, 0, OptionArg.NONE, ref version, "Display version number", null }, { "quiet", 'q', 0, OptionArg.NONE, ref quiet_mode, "Do not print messages to the console", null }, { OPTION_REMAINING, 0, 0, OptionArg.FILENAME_ARRAY, ref sources, null, "FILE..." }, { null } }; + private const string DEFAULT_COLORS = "error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01"; private int quit () { if (context.report.get_errors () == 0) { @@ -97,12 +102,37 @@ public class Vala.DBusGen { } } + static bool option_parse_color (string option_name, string? val, void* data) throws OptionError { + switch (val) { + case "auto": colored_output = Report.Colored.AUTO; break; + case "never": colored_output = Report.Colored.NEVER; break; + case null: + case "always": colored_output = Report.Colored.ALWAYS; break; + default: throw new OptionError.FAILED ("Invalid --color argument '%s'", val); + } + return true; + } + private int run () { context = new CodeContext (); context.report.enable_warnings = !disable_warnings; context.vapi_directories = vapi_directories; context.report.set_verbose_errors (!quiet_mode); + + if (disable_colored_output) { + colored_output = Report.Colored.NEVER; + } + + if (colored_output != Report.Colored.NEVER) { + unowned string env_colors = Environment.get_variable ("VALA_COLORS"); + if (env_colors != null) { + context.report.set_colors (env_colors, colored_output); + } else { + context.report.set_colors (DEFAULT_COLORS, colored_output); + } + } + CodeContext.push (context); context.set_target_profile (Profile.GOBJECT); diff --git a/doc/valadbusgen.1 b/doc/valadbusgen.1 index 07d8e82ea..2c0188e1a 100644 --- a/doc/valadbusgen.1 +++ b/doc/valadbusgen.1 @@ -41,6 +41,17 @@ Namespace to strip \fB\-\-dbus\-timeout\fR DBus timeout .TP +\fB\-\-no\-color\fR +Disable colored output, alias for \fB\-\-color\fR=\fI\,never\/\fR +.TP +\fB\-\-color\fR=\fI\,WHEN\/\fR +Enable color output, options are 'always', 'never', or 'auto' +.RS +When no value is given \fIalways\fR is implied. When neither \fB--color\fR +or \fB--no-color\fR are declared then \fB--color\fR=\fIauto\fR is used where +output is colored when stderr is a terminal. +.RE +.TP \fB\-\-version\fR Display version number .TP