Files
SabreTools/SabreTools.Core/Prepare.cs

55 lines
2.0 KiB
C#
Raw Normal View History

using System;
2020-12-11 23:06:40 -08:00
using System.IO;
using System.Reflection;
2020-12-08 13:23:59 -08:00
namespace SabreTools.Core
{
2019-02-08 20:32:49 -08:00
/// <summary>
/// Generic console preparation for program output
/// </summary>
2020-08-01 23:10:23 -07:00
public static class Prepare
2019-02-08 20:32:49 -08:00
{
2020-12-11 23:06:40 -08:00
/// <summary>
/// The current toolset version to be used by all child applications
/// </summary>
2023-01-19 18:03:45 -08:00
public readonly static string Version = $"v1.1.2";
2019-02-08 20:32:49 -08:00
/// <summary>
/// Readies the console and outputs the header
/// </summary>
2020-08-01 23:10:23 -07:00
/// <param name="program">The name to be displayed as the program</param>
public static void SetConsoleHeader(string program)
2019-02-08 20:32:49 -08:00
{
// 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)}+";
2020-12-11 23:06:40 -08:00
string mid = $"{program} {Version}";
mid = $"|{mid.PadLeft(((width - mid.Length) / 2) + mid.Length).PadRight(width)}|";
2016-04-18 20:04:38 -07:00
2019-02-08 20:32:49 -08:00
// If we're outputting to console, do fancy things
2024-02-28 19:49:09 -05:00
#if NET452_OR_GREATER || NETCOREAPP
2019-02-08 20:32:49 -08:00
if (!Console.IsOutputRedirected)
{
// Set the console to ready state
2020-12-14 16:24:04 -08:00
ConsoleColor formertext = Console.ForegroundColor;
ConsoleColor formerback = Console.BackgroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Blue;
2016-04-20 11:50:03 -07:00
2020-12-11 23:06:40 -08:00
Console.Title = $"{program} {Version}";
2016-04-18 20:04:38 -07:00
2019-02-08 20:32:49 -08:00
// Output the header
Console.WriteLine(border);
Console.WriteLine(mid);
Console.WriteLine(border);
Console.WriteLine();
2016-04-18 20:04:38 -07:00
2019-02-08 20:32:49 -08:00
// Return the console to the original text and background colors
2020-12-14 16:24:04 -08:00
Console.ForegroundColor = formertext;
Console.BackgroundColor = formerback;
2020-08-01 23:10:23 -07:00
}
2024-02-28 19:49:09 -05:00
#endif
2020-08-01 23:10:23 -07:00
}
2019-02-08 20:32:49 -08:00
}
}