From c27511dd669f0d22621b7118deb54c36ea9f5456 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Fri, 9 May 2025 17:05:47 +0300 Subject: [PATCH] Add colors to verbose utilities --- ...CheckConditionalTraitInterfaceOverrides.cs | 3 ++ .../CheckExplicitInterfacesCommand.cs | 3 ++ .../UtilityCommands/CheckYaml.cs | 12 +++++- .../UtilityCommands/UpdateMapCommand.cs | 11 +++++ .../UtilityCommands/UpdateModCommand.cs | 43 ++++++++++++++++--- 5 files changed, 64 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckConditionalTraitInterfaceOverrides.cs b/OpenRA.Mods.Common/UtilityCommands/CheckConditionalTraitInterfaceOverrides.cs index 0fe1a3986c..f52b7bdc0e 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckConditionalTraitInterfaceOverrides.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckConditionalTraitInterfaceOverrides.cs @@ -57,7 +57,10 @@ namespace OpenRA.Mods.Common.UtilityCommands BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null; if (overridesCreated) { + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0} must override ConditionalTrait's {1} method instead of implementing {2} directly", t.Name, methodName, interfaceType.Name); + Console.ForegroundColor = originalColor; violationCount++; } } diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckExplicitInterfacesCommand.cs b/OpenRA.Mods.Common/UtilityCommands/CheckExplicitInterfacesCommand.cs index 5420677b0b..e1d24bd38d 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckExplicitInterfacesCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckExplicitInterfacesCommand.cs @@ -119,7 +119,10 @@ namespace OpenRA.Mods.Common.UtilityCommands void OnViolation(Type implementor, Type interfaceType, MemberInfo violator) { + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{implementor.Name} must explicitly implement the interface member {interfaceType.Name}.{violator.Name}"); + Console.ForegroundColor = originalColor; violationCount++; } } diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs b/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs index ab155e5534..bf47511b22 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs @@ -28,7 +28,11 @@ namespace OpenRA.Mods.Common.UtilityCommands // mimic Windows compiler error format static void EmitError(string e) { - Console.WriteLine($"OpenRA.Utility(1,1): Error: {e}"); + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; + Console.Write("OpenRA.Utility(1,1): Error:"); + Console.ForegroundColor = originalColor; + Console.WriteLine(e); ++errors; } @@ -38,7 +42,11 @@ namespace OpenRA.Mods.Common.UtilityCommands EmitError(e); else { - Console.WriteLine($"OpenRA.Utility(1,1): Warning: {e}"); + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.Write("OpenRA.Utility(1,1): Warning:"); + Console.ForegroundColor = originalColor; + Console.WriteLine(e); ++warnings; } } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs index 9aeb9135ad..e0c92038f3 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpdateMapCommand.cs @@ -110,18 +110,27 @@ namespace OpenRA.Mods.Common.UtilityCommands // Files are saved after each successful automated rule update mapFiles.Save(); + + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("COMPLETE"); + Console.ForegroundColor = originalColor; if (manualSteps.Count > 0) { + Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" Manual changes are required to complete this update:"); + Console.ForegroundColor = originalColor; foreach (var manualStep in manualSteps) Console.WriteLine(" * " + manualStep.Replace("\n", "\n ")); } } catch (Exception ex) { + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("FAILED"); + Console.ForegroundColor = originalColor; Console.WriteLine(); Console.WriteLine(" The automated changes for this rule were not applied because of an error."); @@ -138,8 +147,10 @@ namespace OpenRA.Mods.Common.UtilityCommands if (externalFilenames.Count > 0) { + Console.WriteLine(); Console.WriteLine("The following shared yaml files referenced by the map have been ignored:"); Console.WriteLine(UpdateUtils.FormatMessageList(externalFilenames)); + Console.WriteLine(); Console.WriteLine("These files are assumed to have already been updated by the --update-mod command"); Console.WriteLine(); } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs index 64f14b0146..c2a3736ecc 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpdateModCommand.cs @@ -151,6 +151,36 @@ namespace OpenRA.Mods.Common.UtilityCommands Console.WriteLine(format, args); } + static void LogSuccess(StreamWriter logWriter, string format, params object[] args) + { + logWriter.WriteLine(format, args); + + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine(format, args); + Console.ForegroundColor = originalColor; + } + + static void LogError(StreamWriter logWriter, string format, params object[] args) + { + logWriter.WriteLine(format, args); + + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(format, args); + Console.ForegroundColor = originalColor; + } + + static void LogWarning(StreamWriter logWriter, string format, params object[] args) + { + logWriter.WriteLine(format, args); + + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(format, args); + Console.ForegroundColor = originalColor; + } + static void LogLine(StreamWriter logWriter) { logWriter.WriteLine(); @@ -176,12 +206,11 @@ namespace OpenRA.Mods.Common.UtilityCommands { Log(logWriter, " Updating mod... "); manualSteps.AddRange(UpdateUtils.UpdateMod(modData, rule, out allFiles, externalFilenames)); - LogLine(logWriter, "COMPLETE"); + LogSuccess(logWriter, "COMPLETE"); } catch (Exception ex) { - Console.WriteLine("FAILED"); - + LogError(logWriter, "FAILED"); LogLine(logWriter); LogLine(logWriter, " The automated changes for this rule were not applied because of an error."); LogLine(logWriter, " After the issue reported below is resolved you should run the updater"); @@ -211,7 +240,7 @@ namespace OpenRA.Mods.Common.UtilityCommands } catch (Exception ex) { - LogLine(logWriter, "FAILED"); + LogError(logWriter, "FAILED"); LogLine(logWriter); LogLine(logWriter, " The automated changes for this rule were not applied because of an error."); LogLine(logWriter, " After the issue reported below is resolved you should run the updater"); @@ -230,7 +259,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (mapsFailed) continue; - LogLine(logWriter, "COMPLETE"); + LogSuccess(logWriter, "COMPLETE"); } else LogLine(logWriter, "SKIPPED"); @@ -240,7 +269,7 @@ namespace OpenRA.Mods.Common.UtilityCommands if (manualSteps.Count > 0) { - LogLine(logWriter, " Manual changes are required to complete this update:"); + LogWarning(logWriter, " Manual changes are required to complete this update:"); LogLine(logWriter, UpdateUtils.FormatMessageList(manualSteps, 1)); } @@ -249,8 +278,10 @@ namespace OpenRA.Mods.Common.UtilityCommands if (externalFilenames.Count > 0) { + LogLine(logWriter); LogLine(logWriter, "The following external mod files have been ignored:"); LogLine(logWriter, UpdateUtils.FormatMessageList(externalFilenames)); + LogLine(logWriter); LogLine(logWriter, "These files should be updated by running --update-mod on the referenced mod(s)"); LogLine(logWriter); }