2016-04-06 14:19:01 -07:00
|
|
|
|
using System;
|
2020-12-11 23:06:40 -08:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Reflection;
|
2016-04-06 14:19:01 -07:00
|
|
|
|
|
2020-12-08 13:23:59 -08:00
|
|
|
|
namespace SabreTools.Core
|
2016-04-06 00:01:54 -07:00
|
|
|
|
{
|
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>
|
|
|
|
|
|
//public readonly static string Version = $"v1.0.4";
|
|
|
|
|
|
public readonly static string Version = $"v1.0.4-{File.GetCreationTime(Assembly.GetExecutingAssembly().Location):yyyy-MM-dd HH:mm:ss}";
|
|
|
|
|
|
|
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;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
string border = $"+{new string('-', width)}+";
|
2020-12-11 23:06:40 -08:00
|
|
|
|
string mid = $"{program} {Version}";
|
2020-06-10 22:37:19 -07:00
|
|
|
|
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
|
|
|
|
|
|
if (!Console.IsOutputRedirected)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Set the console to ready state
|
|
|
|
|
|
ConsoleColor formertext = ConsoleColor.White;
|
|
|
|
|
|
ConsoleColor formerback = ConsoleColor.Black;
|
2020-06-11 10:22:00 -07:00
|
|
|
|
if (!MonoOrCoreEnvironment)
|
2019-02-08 20:32:49 -08:00
|
|
|
|
{
|
|
|
|
|
|
Console.SetBufferSize(Console.BufferWidth, 999);
|
|
|
|
|
|
formertext = Console.ForegroundColor;
|
|
|
|
|
|
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-06-11 10:22:00 -07:00
|
|
|
|
if (!MonoOrCoreEnvironment)
|
2019-02-08 20:32:49 -08:00
|
|
|
|
{
|
|
|
|
|
|
Console.ForegroundColor = formertext;
|
|
|
|
|
|
Console.BackgroundColor = formerback;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-01 23:10:23 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns true if running in a Mono or .NET Core environment
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static bool MonoOrCoreEnvironment
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
#if NET_FRAMEWORK
|
|
|
|
|
|
return Type.GetType("Mono.Runtime") != null;
|
|
|
|
|
|
#else
|
|
|
|
|
|
return true;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-02-08 20:32:49 -08:00
|
|
|
|
}
|
2016-04-06 00:01:54 -07:00
|
|
|
|
}
|