diff --git a/src/NosCore.Shared/I18N/Logger.cs b/src/NosCore.Shared/I18N/Logger.cs index afe8c1e..080e65b 100644 --- a/src/NosCore.Shared/I18N/Logger.cs +++ b/src/NosCore.Shared/I18N/Logger.cs @@ -14,6 +14,8 @@ namespace NosCore.Shared.I18N { public static class Logger { + private const int HeadlessWindowWidth = 21; + private static IConfigurationRoot? _configuration; private static readonly string[] AsciiTitle = { @@ -40,16 +42,29 @@ public static void PrintHeader(string text) var titleLogger = new LoggerConfiguration() .WriteTo.Console(outputTemplate: "{Message:lj}{NewLine}") .CreateLogger(); - var offset = Console.WindowWidth / 2 + text?.Length / 2; - var separator = new string('=', Console.WindowHeight > 0 ? Console.WindowWidth - 1 : 20); + var width = GetWindowWidth(); + var offset = width / 2 + text?.Length / 2; + var separator = new string('=', width - 1); titleLogger.Information(separator); foreach (var s in AsciiTitle) { - titleLogger.Information(string.Format(CultureInfo.CurrentCulture, "{0," + (Console.WindowWidth / 2 + s.Length / 2) + "}", s)); + titleLogger.Information(string.Format(CultureInfo.CurrentCulture, "{0," + (width / 2 + s.Length / 2) + "}", s)); } titleLogger.Information(string.Format(CultureInfo.CurrentCulture, "{0," + offset + "}", text)); titleLogger.Information(separator); } + + private static int GetWindowWidth() + { + try + { + return Console.WindowHeight > 0 ? Console.WindowWidth : HeadlessWindowWidth; + } + catch (IOException) + { + return HeadlessWindowWidth; + } + } } } \ No newline at end of file diff --git a/src/NosCore.Shared/NosCore.Shared.csproj b/src/NosCore.Shared/NosCore.Shared.csproj index 4f18100..42a8d25 100644 --- a/src/NosCore.Shared/NosCore.Shared.csproj +++ b/src/NosCore.Shared/NosCore.Shared.csproj @@ -12,7 +12,7 @@ https://github.com/NosCoreIO/NosCore.Dao.git nostale, noscore, nostale private server source, nostale emulator - 6.0.0 + 6.0.1 false NosCore's Shared Components @@ -29,12 +29,12 @@ - + - - + + - + diff --git a/test/NosCore.Shared.Tests/NosCore.Shared.Tests.csproj b/test/NosCore.Shared.Tests/NosCore.Shared.Tests.csproj index 7022ef6..b187c5d 100644 --- a/test/NosCore.Shared.Tests/NosCore.Shared.Tests.csproj +++ b/test/NosCore.Shared.Tests/NosCore.Shared.Tests.csproj @@ -8,11 +8,11 @@ - - + + - - + +