From 6ad9e5f578b678fb0b9b173791a1d32f955b2f66 Mon Sep 17 00:00:00 2001 From: Karl Essinger Date: Mon, 13 Nov 2023 18:27:08 +0100 Subject: [PATCH] Added options to disable LA setting the terminal title (#76) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed line endings setting in .editorconfig * Added -t, --noTerminalTitle arguments, set_terminal_title config entry * Fixed config wizard not asking about heartbeat monitoring * Update README.md * no u * Unfixed line endings --------- Co-authored-by: ɅLΞX <123724383+ALEXWARELLC@users.noreply.github.com> --- Core/ConfigWizard.cs | 2 ++ Core/LocalAdmin.cs | 30 +++++++++++++++++++++++------- Core/TcpServer.cs | 4 ++-- IO/Config.cs | 9 +++++++++ README.md | 1 + 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Core/ConfigWizard.cs b/Core/ConfigWizard.cs index 8229622..252b9e0 100644 --- a/Core/ConfigWizard.cs +++ b/Core/ConfigWizard.cs @@ -47,6 +47,8 @@ public static void RunConfigWizard(bool useDefault) } LocalAdmin.Configuration.RestartOnCrash = BoolInput("Should the server be automatically restarted after a crash?"); + LocalAdmin.Configuration.EnableHeartbeat = BoolInput("Should LocalAdmin attempt to detect silent crashes using heartbeat monitoring?"); + LocalAdmin.Configuration.SetTerminalTitle = BoolInput("Should the LocalAdmin status be written in the terminal title?"); LocalAdmin.Configuration.LaLiveViewUseUtc = !BoolInput("Should timestamps in the LocalAdmin live view use server timezone (otherwise UTC time will be use)?"); string? withoutTimezone = null; diff --git a/Core/LocalAdmin.cs b/Core/LocalAdmin.cs index 5257735..767da49 100644 --- a/Core/LocalAdmin.cs +++ b/Core/LocalAdmin.cs @@ -64,7 +64,7 @@ public sealed class LocalAdmin : IDisposable $"LocalAdmin v. {VersionString}" + (GamePort != 0 ? $" | Port: {GamePort}" : string.Empty) + (_processId.HasValue ? $" | PID: {_processId}" : string.Empty); - internal static bool NoSetCursor, PrintControlMessages, AutoFlush = true, EnableLogging = true, NoPadding, DismissPluginsSecurityWarning; + internal static bool NoSetCursor, PrintControlMessages, AutoFlush = true, EnableLogging = true, NoPadding, DismissPluginsSecurityWarning, NoTerminalTitle; internal ShutdownAction ExitAction = ShutdownAction.Crash; internal bool DisableExitActionSignals; @@ -120,8 +120,6 @@ internal LocalAdmin() internal async Task Start(string[] args) { Singleton = this; - Console.Title = BaseWindowTitle; - HeartbeatStopwatch.Reset(); if (!PathManager.CorrectPathFound && !args.Contains("--skipHomeCheck", StringComparer.Ordinal)) @@ -291,6 +289,9 @@ internal async Task Start(string[] args) case 'a': NoPadding = true; break; + case 't': + NoTerminalTitle = true; + break; } } } @@ -366,6 +367,10 @@ internal async Task Start(string[] args) capture = CaptureArgs.LogEntriesLimit; break; + case "--noTerminalTitle": + NoTerminalTitle = true; + break; + case "--": capture = CaptureArgs.ArgsPassthrough; break; @@ -474,6 +479,8 @@ internal async Task Start(string[] args) } } + SetTerminalTitle(BaseWindowTitle); + if (reconfigure) ConfigWizard.RunConfigWizard(useDefault); @@ -564,9 +571,7 @@ private void StartSession() TerminateGame(); Menu(); - - Console.Title = BaseWindowTitle; - + SetTerminalTitle(BaseWindowTitle); Logger.Initialize(); ConsoleUtil.WriteLine($"Started new session on port {GamePort}.", ConsoleColor.DarkGreen); @@ -787,7 +792,7 @@ private void RunScpsl() _gameProcess = Process.Start(startInfo); _processId = _gameProcess!.Id; - Console.Title = BaseWindowTitle; + SetTerminalTitle(BaseWindowTitle); ConsoleUtil.WriteLine("Game process started with PID: " + _processId, ConsoleColor.DarkGreen); @@ -1140,4 +1145,15 @@ async void HeartbeatMonitoringMethod() { Exit(0); } + + /// + /// Sets the terminal title if not disabled in the config or by command line arguments + /// + public static void SetTerminalTitle(string terminalTitle) + { + if (!NoTerminalTitle && (Configuration?.SetTerminalTitle ?? false)) + { + Console.Title = terminalTitle; + } + } } \ No newline at end of file diff --git a/Core/TcpServer.cs b/Core/TcpServer.cs index fc54818..2f17163 100644 --- a/Core/TcpServer.cs +++ b/Core/TcpServer.cs @@ -139,11 +139,11 @@ public void Start() break; case OutputCodes.IdleEnter: - Console.Title = "[IDLE] " + LocalAdmin.BaseWindowTitle; + LocalAdmin.SetTerminalTitle("[IDLE] " + LocalAdmin.BaseWindowTitle); break; case OutputCodes.IdleExit: - Console.Title = LocalAdmin.BaseWindowTitle; + LocalAdmin.SetTerminalTitle(LocalAdmin.BaseWindowTitle); break; case OutputCodes.ExitActionReset: diff --git a/IO/Config.cs b/IO/Config.cs index 746e999..e5a1a3b 100644 --- a/IO/Config.cs +++ b/IO/Config.cs @@ -10,6 +10,7 @@ public class Config public bool RestartOnCrash = true; public bool EnableHeartbeat = true; + public bool SetTerminalTitle = true; public bool LaLiveViewUseUtc; public bool LaShowStdoutStderr; @@ -44,6 +45,9 @@ public string SerializeConfig() sb.Append("enable_heartbeat: "); sb.AppendLine(EnableHeartbeat.ToString().ToLowerInvariant()); + sb.Append("set_terminal_title: "); + sb.AppendLine(SetTerminalTitle.ToString().ToLowerInvariant()); + sb.Append("la_live_view_use_utc: "); sb.AppendLine(LaLiveViewUseUtc.ToString().ToLowerInvariant()); @@ -130,6 +134,10 @@ public static Config DeserializeConfig(string[] lines) cfg.EnableHeartbeat = b; break; + case "set_terminal_title" when bool.TryParse(sp[1], out var b): + cfg.SetTerminalTitle = b; + break; + case "la_live_view_use_utc" when bool.TryParse(sp[1], out var b): cfg.LaLiveViewUseUtc = b; break; @@ -237,6 +245,7 @@ public override string ToString() sb.AppendLine(RestartOnCrash ? "- Server will be automatically restarted after a crash." : "- Server will NOT be automatically restarted after a crash."); sb.AppendLine(EnableHeartbeat ? "- LocalAdmin will attempt to detect silent server crashes (heartbeat enabled)." : "- LocalAdmin will NOT attempt to detect silent server crashes (heartbeat DISABLED)."); + sb.AppendLine(SetTerminalTitle ? "- LocalAdmin will attempt to show its current status in your terminal title." : "- LocalAdmin will NOT attempt to show its current status in your terminal title."); sb.AppendLine(LaLiveViewUseUtc ? "- LocalAdmin live view will use UTC timezone." : "- LocalAdmin live view will use local timezone."); sb.AppendLine($"- LocalAdmin live will use the following timestamp format: {LaLiveViewTimeFormat}"); sb.AppendLine($"- UTC timezone will be displayed as \"{(LaLogsUseZForUtc ? "Z" : "+00:00")}\"."); diff --git a/README.md b/README.md index 06a2f48..943de2c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Linux: `./LocalAdmin [port] [arguments] [-- arguments passthrough]` | --noLogs | -l | Disables LocalAdmin logging. | | --noAutoFlush | -n | Disables auto flush of LocalAdmin log files.
**Not compatible with --noLogs argument.** | | --noAlign | -a | Disables multiline log entries alignment. | +| --noTerminalTitle | -t | Disables LocalAdmin status in the terminal title. | | --dismissPluginManagerSecurityWarning | | Dismisses Plugin Manager security warning. | | --disableTrueColor | | Disables True Color output. | | --skipHomeCheck | | Skips `home` env var checking on startup (linux only). |