diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index af7a3d7c81..50da066c52 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -489,7 +489,7 @@ namespace Tgstation.Server.Host.Components finally { if (originalConsoleTitle != null) - console.Title = originalConsoleTitle; + console.SetTitle(originalConsoleTitle); } } catch (Exception ex) @@ -569,7 +569,7 @@ namespace Tgstation.Server.Host.Components try { logger.LogInformation("{versionString}", assemblyInformationProvider.VersionString); - console.Title = assemblyInformationProvider.VersionString; + console.SetTitle(assemblyInformationProvider.VersionString); CheckSystemCompatibility(); diff --git a/src/Tgstation.Server.Host/IO/Console.cs b/src/Tgstation.Server.Host/IO/Console.cs index ae6efa4ed7..6a94540bb0 100644 --- a/src/Tgstation.Server.Host/IO/Console.cs +++ b/src/Tgstation.Server.Host/IO/Console.cs @@ -5,8 +5,6 @@ using System.Threading.Tasks; using Tgstation.Server.Host.System; -#nullable disable - namespace Tgstation.Server.Host.IO { /// @@ -15,13 +13,9 @@ namespace Tgstation.Server.Host.IO sealed class Console : IConsole, IDisposable { /// - public string Title - { - get => platformIdentifier.IsWindows - ? global::System.Console.Title - : null; - set => global::System.Console.Title = value; - } + public string? Title => platformIdentifier.IsWindows + ? global::System.Console.Title + : null; /// public bool Available => Environment.UserInteractive; @@ -91,7 +85,8 @@ namespace Tgstation.Server.Host.IO // TODO: Make this better: https://stackoverflow.com/questions/9479573/how-to-interrupt-console-readline CheckAvailable(); if (!usePasswordChar) - return global::System.Console.ReadLine(); + return global::System.Console.ReadLine() + ?? throw new InvalidOperationException("Console input has been closed!"); var passwordBuilder = new StringBuilder(); do @@ -126,7 +121,7 @@ namespace Tgstation.Server.Host.IO .WaitAsync(cancellationToken); /// - public Task WriteAsync(string text, bool newLine, CancellationToken cancellationToken) => Task.Factory.StartNew( + public Task WriteAsync(string? text, bool newLine, CancellationToken cancellationToken) => Task.Factory.StartNew( () => { CheckAvailable(); @@ -145,6 +140,13 @@ namespace Tgstation.Server.Host.IO DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); + /// + public void SetTitle(string newTitle) + { + ArgumentNullException.ThrowIfNull(newTitle); + global::System.Console.Title = newTitle; + } + /// /// Assert that the is available, throwing an otherwise. /// diff --git a/src/Tgstation.Server.Host/IO/IConsole.cs b/src/Tgstation.Server.Host/IO/IConsole.cs index cc71295c55..ee1e948891 100644 --- a/src/Tgstation.Server.Host/IO/IConsole.cs +++ b/src/Tgstation.Server.Host/IO/IConsole.cs @@ -1,8 +1,6 @@ using System.Threading; using System.Threading.Tasks; -#nullable disable - namespace Tgstation.Server.Host.IO { /// @@ -13,7 +11,7 @@ namespace Tgstation.Server.Host.IO /// /// Gets or sets the window's title. Can return if getting the console title is not supported. /// - string Title { get; set; } + string? Title { get; } /// /// If the is visible to the user. @@ -32,7 +30,7 @@ namespace Tgstation.Server.Host.IO /// If there should be a new line after the . /// The for the operation. /// A representing the running operation. - Task WriteAsync(string text, bool newLine, CancellationToken cancellationToken); + Task WriteAsync(string? text, bool newLine, CancellationToken cancellationToken); /// /// Wait for a key press on the . @@ -48,5 +46,11 @@ namespace Tgstation.Server.Host.IO /// The for the operation. /// A resulting in the read by the . Task ReadLineAsync(bool usePasswordChar, CancellationToken cancellationToken); + + /// + /// Sets a console window. + /// + /// The new . + void SetTitle(string newTitle); } } diff --git a/src/Tgstation.Server.Host/Setup/SetupWizard.cs b/src/Tgstation.Server.Host/Setup/SetupWizard.cs index ba82f4bc18..c8007f16b5 100644 --- a/src/Tgstation.Server.Host/Setup/SetupWizard.cs +++ b/src/Tgstation.Server.Host/Setup/SetupWizard.cs @@ -1107,7 +1107,7 @@ namespace Tgstation.Server.Host.Setup return; originalConsoleTitle = console.Title; - console.Title = $"{assemblyInformationProvider.VersionString} Setup Wizard"; + console.SetTitle($"{assemblyInformationProvider.VersionString} Setup Wizard"); } // Link passed cancellationToken with cancel key press @@ -1197,7 +1197,7 @@ namespace Tgstation.Server.Host.Setup { await finalTask; if (originalConsoleTitle != null) - console.Title = originalConsoleTitle; + console.SetTitle(originalConsoleTitle); } } }