Skip to content

Commit d55524e

Browse files
erwan-jolyclaude
andauthored
fix: PrintHeader kills headless startup when no console is attached (#258)
* chore: bump all NuGet packages to latest Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: PrintHeader kills headless startup when no console is attached Console.WindowWidth/WindowHeight throw IOException when the process has no console at all (Windows service, container, detached process manager), so the banner took the server down before it did any work. Read the width once through a guarded helper and fall back to the same narrow layout already used when the window height is unknown. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent d42de0d commit d55524e

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/NosCore.Shared/I18N/Logger.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace NosCore.Shared.I18N
1414
{
1515
public static class Logger
1616
{
17+
private const int HeadlessWindowWidth = 21;
18+
1719
private static IConfigurationRoot? _configuration;
1820
private static readonly string[] AsciiTitle =
1921
{
@@ -40,16 +42,29 @@ public static void PrintHeader(string text)
4042
var titleLogger = new LoggerConfiguration()
4143
.WriteTo.Console(outputTemplate: "{Message:lj}{NewLine}")
4244
.CreateLogger();
43-
var offset = Console.WindowWidth / 2 + text?.Length / 2;
44-
var separator = new string('=', Console.WindowHeight > 0 ? Console.WindowWidth - 1 : 20);
45+
var width = GetWindowWidth();
46+
var offset = width / 2 + text?.Length / 2;
47+
var separator = new string('=', width - 1);
4548
titleLogger.Information(separator);
4649
foreach (var s in AsciiTitle)
4750
{
48-
titleLogger.Information(string.Format(CultureInfo.CurrentCulture, "{0," + (Console.WindowWidth / 2 + s.Length / 2) + "}", s));
51+
titleLogger.Information(string.Format(CultureInfo.CurrentCulture, "{0," + (width / 2 + s.Length / 2) + "}", s));
4952
}
5053

5154
titleLogger.Information(string.Format(CultureInfo.CurrentCulture, "{0," + offset + "}", text));
5255
titleLogger.Information(separator);
5356
}
57+
58+
private static int GetWindowWidth()
59+
{
60+
try
61+
{
62+
return Console.WindowHeight > 0 ? Console.WindowWidth : HeadlessWindowWidth;
63+
}
64+
catch (IOException)
65+
{
66+
return HeadlessWindowWidth;
67+
}
68+
}
5469
}
5570
}

src/NosCore.Shared/NosCore.Shared.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<RepositoryUrl>https://github.com/NosCoreIO/NosCore.Dao.git</RepositoryUrl>
1313
<PackageIconUrl></PackageIconUrl>
1414
<PackageTags>nostale, noscore, nostale private server source, nostale emulator</PackageTags>
15-
<Version>6.0.0</Version>
15+
<Version>6.0.1</Version>
1616
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1717
<Description>NosCore's Shared Components</Description>
1818
<PackageLicenseExpression></PackageLicenseExpression>

0 commit comments

Comments
 (0)