diff --git a/RombaSharp/Features/Version.cs b/RombaSharp/Features/Version.cs index 55512b53..a1349e1f 100644 --- a/RombaSharp/Features/Version.cs +++ b/RombaSharp/Features/Version.cs @@ -27,7 +27,7 @@ namespace RombaSharp.Features if (!base.ProcessFeatures(features)) return false; - logger.User($"RombaSharp version: {Prepare.Version}"); + logger.User($"RombaSharp version: {Globals.Version}"); return true; } } diff --git a/RombaSharp/Program.cs b/RombaSharp/Program.cs index 1af86a20..1436da4b 100644 --- a/RombaSharp/Program.cs +++ b/RombaSharp/Program.cs @@ -104,7 +104,7 @@ namespace RombaSharp if (!Console.IsOutputRedirected && feature.ScriptMode) { Console.Clear(); - Prepare.SetConsoleHeader("SabreTools"); + Globals.SetConsoleHeader("SabreTools"); } // Now process the current feature diff --git a/SabreTools.Core/Globals.cs b/SabreTools.Core/Globals.cs index fe4c9436..4cf91fea 100644 --- a/SabreTools.Core/Globals.cs +++ b/SabreTools.Core/Globals.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace SabreTools.Core { /// - /// Globally-accessible objects for the library + /// Globally-accessible functionality /// public class Globals { @@ -30,5 +30,42 @@ namespace SabreTools.Core MaxDegreeOfParallelism = MaxThreads }; #endif + + /// + /// Readies the console and outputs the header + /// + /// The name to be displayed as the program + public static void SetConsoleHeader(string program) + { + // Dynamically create the header string, adapted from http://stackoverflow.com/questions/8200661/how-to-align-string-in-fixed-length-string + int width = Console.WindowWidth - 3; + string border = $"+{new string('-', width)}+"; + string mid = $"{program} {Globals.Version}"; + mid = $"|{mid.PadLeft(((width - mid.Length) / 2) + mid.Length).PadRight(width)}|"; + + // If we're outputting to console, do fancy things +#if NET452_OR_GREATER || NETCOREAPP + if (!Console.IsOutputRedirected) + { + // Set the console to ready state + ConsoleColor formertext = Console.ForegroundColor; + ConsoleColor formerback = Console.BackgroundColor; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.BackgroundColor = ConsoleColor.Blue; + + Console.Title = $"{program} {Globals.Version}"; + + // Output the header + Console.WriteLine(border); + Console.WriteLine(mid); + Console.WriteLine(border); + Console.WriteLine(); + + // Return the console to the original text and background colors + Console.ForegroundColor = formertext; + Console.BackgroundColor = formerback; + } +#endif + } } } diff --git a/SabreTools.Core/Prepare.cs b/SabreTools.Core/Prepare.cs deleted file mode 100644 index f87c7884..00000000 --- a/SabreTools.Core/Prepare.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; - -namespace SabreTools.Core -{ - /// - /// Generic console preparation for program output - /// - public static class Prepare - { - /// - /// Readies the console and outputs the header - /// - /// The name to be displayed as the program - public static void SetConsoleHeader(string program) - { - // Dynamically create the header string, adapted from http://stackoverflow.com/questions/8200661/how-to-align-string-in-fixed-length-string - int width = Console.WindowWidth - 3; - string border = $"+{new string('-', width)}+"; - string mid = $"{program} {Globals.Version}"; - mid = $"|{mid.PadLeft(((width - mid.Length) / 2) + mid.Length).PadRight(width)}|"; - - // If we're outputting to console, do fancy things -#if NET452_OR_GREATER || NETCOREAPP - if (!Console.IsOutputRedirected) - { - // Set the console to ready state - ConsoleColor formertext = Console.ForegroundColor; - ConsoleColor formerback = Console.BackgroundColor; - Console.ForegroundColor = ConsoleColor.Yellow; - Console.BackgroundColor = ConsoleColor.Blue; - - Console.Title = $"{program} {Globals.Version}"; - - // Output the header - Console.WriteLine(border); - Console.WriteLine(mid); - Console.WriteLine(border); - Console.WriteLine(); - - // Return the console to the original text and background colors - Console.ForegroundColor = formertext; - Console.BackgroundColor = formerback; - } -#endif - } - } -} diff --git a/SabreTools/Features/Update.cs b/SabreTools/Features/Update.cs index 03112913..a99ee628 100644 --- a/SabreTools/Features/Update.cs +++ b/SabreTools/Features/Update.cs @@ -131,10 +131,10 @@ namespace SabreTools.Features Header.SetFieldValue(Models.Metadata.Header.CategoryKey, "DiffDAT"); if (string.IsNullOrWhiteSpace(Header.GetStringFieldValue(Models.Metadata.Header.AuthorKey))) - Header.SetFieldValue(Models.Metadata.Header.AuthorKey, $"SabreTools {Prepare.Version}"); + Header.SetFieldValue(Models.Metadata.Header.AuthorKey, $"SabreTools {Globals.Version}"); if (string.IsNullOrWhiteSpace(Header.GetStringFieldValue(Models.Metadata.Header.CommentKey))) - Header.SetFieldValue(Models.Metadata.Header.CommentKey, $"Generated by SabreTools {Prepare.Version}"); + Header.SetFieldValue(Models.Metadata.Header.CommentKey, $"Generated by SabreTools {Globals.Version}"); } // If no update fields are set, default to Names diff --git a/SabreTools/Features/Version.cs b/SabreTools/Features/Version.cs index 6c0367ad..3299b1bb 100644 --- a/SabreTools/Features/Version.cs +++ b/SabreTools/Features/Version.cs @@ -27,7 +27,7 @@ namespace SabreTools.Features if (!base.ProcessFeatures(features)) return false; - logger.User($"SabreTools version: {Prepare.Version}"); + logger.User($"SabreTools version: {Globals.Version}"); return true; } } diff --git a/SabreTools/Program.cs b/SabreTools/Program.cs index 87c9fae7..7e8063c5 100644 --- a/SabreTools/Program.cs +++ b/SabreTools/Program.cs @@ -104,7 +104,7 @@ namespace SabreTools if (!Console.IsOutputRedirected && feature.ScriptMode) { Console.Clear(); - Prepare.SetConsoleHeader("SabreTools"); + Globals.SetConsoleHeader("SabreTools"); } // Now process the current feature