Minecraft-Console-Client/MinecraftClient/Commands/Debug.cs
BruceChen 8456e363f5
TUI for MCC (#2976)
* feat: implement interactive TUI inventory viewer

- Added InventoryTui command to open an interactive terminal user interface for inventory management.
- Introduced InventoryApp and InventoryMainView classes for TUI layout and functionality.
- Created InventoryViewModel and SlotViewModel to manage inventory data and display.
- Integrated Consolonia for enhanced console UI experience.
- Updated McClient to support console message handling during TUI operation.

These changes enhance user interaction with inventory management in Minecraft Console Client.

* feat: enhance debugging workflow with mcc-debug.sh and TUI support

- Introduced mcc-debug.sh for streamlined one-step build, server start, and MCC launch.
- Added TUI mode for improved user experience during debugging sessions.
- Updated mcc-env.sh to include new debug helpers and TUI mode functionality.
- Enhanced SKILL.md with detailed instructions for using the new debugging tools and console modes.

These changes significantly improve the debugging process for Minecraft Console Client, making it more efficient and user-friendly.

* feat: introduce TUI console backend and related enhancements

- Added ClassicConsoleBackend and TuiConsoleBackend to support different console I/O modes.
- Implemented IConsoleBackend interface for better abstraction of console operations.
- Enhanced ConsoleIO to utilize the new backend structure for input and output handling.
- Introduced MainTuiView and MccTuiApp for a full-screen TUI experience using Avalonia.
- Updated InventoryTuiHost to manage TUI lifecycle and interactions.

These changes significantly improve the console experience in Minecraft Console Client, providing a more flexible and user-friendly interface.

* refactor: remove InventoryTui command implementation

- Deleted the InventoryTui class, which provided an interactive terminal user interface for inventory management.
- This change simplifies the command structure as part of ongoing improvements to the console experience in Minecraft Console Client.

The removal of this command is aligned with recent enhancements to the console backend and user interface.

* refactor: update InventoryMainView and MainTuiView for improved UI handling

- Changed several fields from readonly to mutable in InventoryMainView to allow for dynamic updates.
- Introduced a new McColorParser class for parsing Minecraft color codes and creating colored text blocks.
- Enhanced MainTuiView to support formatted log lines and improved notification handling.
- Updated chat scrolling behavior to ensure better user experience during text input and log display.

These changes streamline the UI components and enhance the overall console experience in Minecraft Console Client.

* feat: enhance command input handling in MainTuiView

- Updated command input to use event routing for better key handling.
- Added support for Ctrl key shortcuts to improve text manipulation (e.g., word deletion, caret movement).
- Implemented text cleaning on input change to prevent newline characters.
- Improved health and food status bar rendering with a new method for building bar text.

These changes significantly enhance the user experience in the TUI by providing more intuitive command input functionality.

* feat: enhance TUI command suggestion functionality

- Introduced a new CommandSuggestion struct for backend-independent suggestion handling.
- Updated ConsoleIO to streamline suggestion updates for both Classic and TUI backends.
- Enhanced MainTuiView to display command suggestions with improved visibility and interaction.
- Increased the maximum number of displayed suggestions from 6 to 10 for better user experience.

These changes significantly improve the command input experience in the TUI, making it more intuitive and user-friendly.

* feat: enhance offline command autocomplete functionality

- Introduced an OfflineAutocompleteHandler to provide command suggestions for offline commands.
- Added support for tab cycling through suggestions in the TUI.
- Improved command input handling to clear suggestions when necessary and manage user input more effectively.
- Updated TuiConsoleBackend to integrate with the new autocomplete feature.

These changes significantly enhance the user experience by making command input more intuitive and responsive in offline scenarios.

* feat: enhance localization and user feedback in TUI

- Updated various TUI components to utilize localized strings for improved user experience.
- Enhanced debug state output with translated labels for better clarity.
- Improved inventory command help messages with localized text.
- Added new translations for console mode descriptions and inventory viewer prompts.

These changes significantly enhance the usability and accessibility of the TUI in Minecraft Console Client, making it more user-friendly and informative.

* feat: enforce localization for user-facing strings in AGENTS.md

- Added guidelines to ensure all user-facing text, including log messages and error messages, is managed through the translation system.
- Specified the use of `Translations.resx` and `Translations.Designer.cs` for localization, emphasizing the importance of avoiding hardcoded strings in source code.

These changes improve the consistency and accessibility of user-facing content across the application.
2026-03-26 02:08:18 +08:00

104 lines
4.7 KiB
C#

using System;
using System.Linq;
using System.Text;
using Brigadier.NET;
using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler;
using MinecraftClient.Scripting;
namespace MinecraftClient.Commands
{
public class Debug : Command
{
public override string CmdName { get { return "debug"; } }
public override string CmdUsage { get { return "debug [on|off|state]"; } }
public override string CmdDesc { get { return Translations.cmd_debug_desc; } }
public override void RegisterCommand(CommandDispatcher<CmdResult> dispatcher)
{
dispatcher.Register(l => l.Literal("help")
.Then(l => l.Literal(CmdName)
.Executes(r => GetUsage(r.Source, string.Empty))
)
);
dispatcher.Register(l => l.Literal(CmdName)
.Executes(r => SetDebugMode(r.Source, true))
.Then(l => l.Literal("on")
.Executes(r => SetDebugMode(r.Source, false, true)))
.Then(l => l.Literal("off")
.Executes(r => SetDebugMode(r.Source, false, false)))
.Then(l => l.Literal("state")
.Executes(r => ShowState(r.Source)))
.Then(l => l.Literal("_help")
.Executes(r => GetUsage(r.Source, string.Empty))
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
);
}
private int GetUsage(CmdResult r, string? cmd)
{
return r.SetAndReturn(cmd switch
{
#pragma warning disable format // @formatter:off
_ => GetCmdDescTranslated(),
#pragma warning restore format // @formatter:on
});
}
private int SetDebugMode(CmdResult r, bool flip, bool mode = false)
{
McClient handler = CmdResult.currentHandler!;
if (flip)
Settings.Config.Logging.DebugMessages = !Settings.Config.Logging.DebugMessages;
else
Settings.Config.Logging.DebugMessages = mode;
handler.Log.DebugEnabled = Settings.Config.Logging.DebugMessages;
if (Settings.Config.Logging.DebugMessages)
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_debug_state_on);
else
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_debug_state_off);
}
private int ShowState(CmdResult r)
{
McClient handler = CmdResult.currentHandler!;
var sb = new StringBuilder();
sb.AppendLine($"§e=== {Translations.cmd_debug_state_header} ===");
sb.AppendLine($"§7{Translations.cmd_debug_state_server,-10}§f{handler.GetServerHost()}:{handler.GetServerPort()}");
sb.AppendLine($"§7{Translations.cmd_debug_state_username,-10}§f{handler.GetUsername()}");
sb.AppendLine($"§7{Translations.cmd_debug_state_protocol,-10}§f{handler.GetProtocolVersion()}");
sb.AppendLine($"§7{Translations.cmd_debug_state_gamemode,-10}§f{handler.GetGamemode()}");
sb.AppendLine($"§7{Translations.cmd_debug_state_health,-10}§f{handler.GetHealth():F1}");
sb.AppendLine($"§7{Translations.cmd_debug_state_food,-10}§f{handler.GetSaturation()}");
var loc = handler.GetCurrentLocation();
sb.AppendLine($"§7{Translations.cmd_debug_state_location,-10}§f{loc.X:F2}, {loc.Y:F2}, {loc.Z:F2}");
sb.AppendLine($"§7{Translations.cmd_debug_state_tps,-10}§f{handler.GetServerTPS():F1}");
sb.AppendLine($"§7{Translations.cmd_debug_state_console,-10}§f{(ConsoleIO.Backend?.GetType().Name ?? "null")}");
var features = new StringBuilder();
features.Append(handler.GetTerrainEnabled() ? "§aTerrain " : "§8Terrain ");
features.Append(handler.GetInventoryEnabled() ? "§aInventory " : "§8Inventory ");
features.Append(handler.GetEntityHandlingEnabled() ? "§aEntity " : "§8Entity ");
sb.AppendLine($"§7{Translations.cmd_debug_state_features,-10}{features}");
sb.AppendLine($"§7{Translations.cmd_debug_state_debug,-10}§f{(Settings.Config.Logging.DebugMessages ? "§aON" : "§cOFF")}");
var bots = handler.GetLoadedChatBots();
sb.AppendLine($"§7{Translations.cmd_debug_state_bots} ({bots.Count}): §f{string.Join(", ", bots.Select(b => b.GetType().Name))}");
var players = handler.GetOnlinePlayers();
sb.AppendLine($"§7{Translations.cmd_debug_state_players,-10}§f{string.Format(Translations.cmd_debug_state_online, players.Length)}");
handler.Log.Info(sb.ToString());
return r.SetAndReturn(CmdResult.Status.Done);
}
}
}