Refactor exit handling and command input in TUI

- Improved the exit process by ensuring the backend shutdown is called after handling offline prompts.
- Enhanced command input history management by encapsulating text setting logic in a dedicated method to prevent event handler interference.
- Adjusted the background color in the color parser for better visibility.
- Increased the sleep duration in the TUI exit guard thread to ensure a smoother shutdown process.
This commit is contained in:
BruceChen 2026-03-26 23:20:10 +08:00
parent 0ceaaead10
commit b33ee7e4a1
4 changed files with 79 additions and 67 deletions

View file

@ -494,10 +494,21 @@ namespace MinecraftClient.Tui
}
string historyText = _commandHistory[_historyIndex];
_commandInput.Text = historyText;
_commandInput.CaretIndex = historyText.Length;
Dispatcher.UIThread.Post(() => _commandInput.CaretIndex = historyText.Length,
DispatcherPriority.Input);
SetCommandText(historyText);
}
private void SetCommandText(string text)
{
_commandInput.TextChanged -= OnCommandTextChanged;
try
{
_commandInput.Text = text;
_commandInput.CaretIndex = text.Length;
}
finally
{
_commandInput.TextChanged += OnCommandTextChanged;
}
}
#endregion

View file

@ -47,6 +47,8 @@ namespace MinecraftClient.Tui
return tb;
}
tb.Background = Brushes.Black;
IBrush currentColor = Brushes.White;
bool bold = false;
bool italic = false;

View file

@ -256,7 +256,7 @@ namespace MinecraftClient.Tui
new Thread(() =>
{
Thread.Sleep(500);
Thread.Sleep(1000);
Environment.Exit(0);
}) { Name = "TUI-Exit-Guard", IsBackground = true }.Start();
}