Skip to content

Commit

Permalink
Added options to disable LA setting the terminal title (#76)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
KarlOfDuty and iamalexrouse authored Nov 13, 2023
1 parent fea3246 commit 6ad9e5f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Core/ConfigWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 23 additions & 7 deletions Core/LocalAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -291,6 +289,9 @@ internal async Task Start(string[] args)
case 'a':
NoPadding = true;
break;
case 't':
NoTerminalTitle = true;
break;
}
}
}
Expand Down Expand Up @@ -366,6 +367,10 @@ internal async Task Start(string[] args)
capture = CaptureArgs.LogEntriesLimit;
break;

case "--noTerminalTitle":
NoTerminalTitle = true;
break;

case "--":
capture = CaptureArgs.ArgsPassthrough;
break;
Expand Down Expand Up @@ -474,6 +479,8 @@ internal async Task Start(string[] args)
}
}

SetTerminalTitle(BaseWindowTitle);

if (reconfigure)
ConfigWizard.RunConfigWizard(useDefault);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1140,4 +1145,15 @@ async void HeartbeatMonitoringMethod()
{
Exit(0);
}

/// <summary>
/// Sets the terminal title if not disabled in the config or by command line arguments
/// </summary>
public static void SetTerminalTitle(string terminalTitle)
{
if (!NoTerminalTitle && (Configuration?.SetTerminalTitle ?? false))
{
Console.Title = terminalTitle;
}
}
}
4 changes: 2 additions & 2 deletions Core/TcpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions IO/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")}\".");
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Linux: `./LocalAdmin [port] [arguments] [-- arguments passthrough]`
| --noLogs | -l | Disables LocalAdmin logging. |
| --noAutoFlush | -n | Disables auto flush of LocalAdmin log files.<br>**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). |
Expand Down

0 comments on commit 6ad9e5f

Please sign in to comment.