Minecraft-Console-Client/tools/mcc-debug.sh

195 lines
6.5 KiB
Bash
Raw Normal View History

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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# shellcheck source=tools/mcc-env.sh
source "$REPO_ROOT/tools/mcc-env.sh"
usage() {
cat <<'EOF'
Usage: tools/mcc-debug.sh [options]
One-step build, server start, and MCC launch for debugging.
Options:
-v, --version VER Server directory name (default: 1.21.11-Vanilla)
-m, --mode MODE Console mode: classic or tui (default: classic)
-p, --port PORT Server port (default: 25565)
--no-build Skip dotnet build
--debug-on Enable debug messages from the start
--file-input Use FileInput mode (classic only; enables mcc-cmd)
-h, --help Show this help
Examples:
tools/mcc-debug.sh # Classic mode, default server
tools/mcc-debug.sh -m tui # TUI mode
tools/mcc-debug.sh -v 1.21.11-Vanilla --debug-on
tools/mcc-debug.sh --file-input # FileInput for script-driven testing
EOF
}
VERSION="1.21.11-Vanilla"
MODE="classic"
PORT="25565"
DO_BUILD=true
DEBUG_ON=false
FILE_INPUT=false
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--version) VERSION="$2"; shift 2 ;;
-m|--mode) MODE="$2"; shift 2 ;;
-p|--port) PORT="$2"; shift 2 ;;
--no-build) DO_BUILD=false; shift ;;
--debug-on) DEBUG_ON=true; shift ;;
--file-input) FILE_INPUT=true; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown option: $1" >&2; usage >&2; exit 1 ;;
esac
done
TEST_ROOT="${TMPDIR:-/tmp}/mcc-debug"
CFG="$TEST_ROOT/MinecraftClient.debug.ini"
MCC_LOG="$TEST_ROOT/mcc-debug.log"
INPUT_FILE="$REPO_ROOT/mcc_input.txt"
SESSION_NAME="mc-${VERSION//\./_}"
mkdir -p "$TEST_ROOT"
echo "=== MCC Debug Session ==="
echo " Server: $VERSION (port $PORT)"
echo " Mode: $MODE"
echo " Config: $CFG"
echo " Log: $MCC_LOG"
echo ""
# --- Build ---
if $DO_BUILD; then
echo "[1/4] Building MCC..."
dotnet build "$REPO_ROOT/MinecraftClient.sln" -c Release -v quiet --nologo
echo " Build OK"
else
echo "[1/4] Build skipped (--no-build)"
fi
# --- Prepare config ---
echo "[2/4] Preparing config..."
cp "$REPO_ROOT/MinecraftClient.ini" "$CFG"
sed -i \
-e 's/Account = { Login = "[^"]*", Password = "[^"]*" }/Account = { Login = "CursorBot", Password = "-" }/' \
-e 's/TerrainAndMovements = false/TerrainAndMovements = true/' \
-e 's/InventoryHandling = false/InventoryHandling = true/' \
-e 's/EntityHandling = false/EntityHandling = true/' \
"$CFG"
if [[ "$MODE" == "tui" ]]; then
sed -i 's/ConsoleMode = "classic"/ConsoleMode = "tui"/' "$CFG"
fi
if $DEBUG_ON; then
sed -i 's/DebugMessages = false/DebugMessages = true/' "$CFG"
fi
echo " Config ready"
# --- Start server ---
echo "[3/4] Starting server $VERSION..."
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
echo " Server already running"
else
# Ensure offline mode
SERVER_DIR="$MCC_SERVERS/$VERSION"
if [[ -f "$SERVER_DIR/server.properties" ]]; then
sed -i 's/^online-mode=.*/online-mode=false/' "$SERVER_DIR/server.properties"
grep -q "^enable-rcon=" "$SERVER_DIR/server.properties" || echo "enable-rcon=true" >> "$SERVER_DIR/server.properties"
grep -q "^rcon.password=" "$SERVER_DIR/server.properties" || echo "rcon.password=test123" >> "$SERVER_DIR/server.properties"
grep -q "^rcon.port=" "$SERVER_DIR/server.properties" || echo "rcon.port=25575" >> "$SERVER_DIR/server.properties"
fi
mc-start "$VERSION" >/dev/null
echo -n " Waiting for server..."
for i in $(seq 1 60); do
if mc-log "$VERSION" 250 2>/dev/null | grep -Fq "Done ("; then
echo " ready (${i}s)"
break
fi
echo -n "."
sleep 1
if [[ $i -eq 60 ]]; then
echo " TIMEOUT"
echo "Server failed to start. Check: tmux attach -t $SESSION_NAME"
exit 1
fi
done
fi
# --- Launch MCC ---
echo "[4/4] Launching MCC in $MODE mode..."
: > "$INPUT_FILE"
rm -f "$MCC_LOG"
MCC_ARGS=("$CFG" "CursorBot" "-" "localhost:$PORT")
if [[ "$MODE" == "tui" ]]; then
# TUI mode: needs a real tty — no pipes or redirects allowed
tmux kill-session -t mcc-debug 2>/dev/null || true
tmux new-session -d -s mcc-debug -x 160 -y 50 \
"cd '$REPO_ROOT' && dotnet run --project MinecraftClient -c Release --no-build -- ${MCC_ARGS[*]}; echo '=== MCC EXITED ==='; sleep 600"
echo ""
echo " TUI mode started in tmux session 'mcc-debug'"
echo " (TUI mode uses a real terminal; log file is not available, use MCC's /debug command)"
echo ""
echo " Attach: tmux attach -t mcc-debug"
echo " Detach: Ctrl+B, D"
echo " Kill MCC: tmux kill-session -t mcc-debug"
echo ""
elif $FILE_INPUT; then
# FileInput mode: run in background, drive via mcc_input.txt
(
cd "$REPO_ROOT"
MCC_FILE_INPUT=1 dotnet run --project MinecraftClient -c Release --no-build -- "${MCC_ARGS[@]}" > "$MCC_LOG" 2>&1
) &
MCC_PID=$!
echo " MCC PID: $MCC_PID"
echo ""
sleep 5
if kill -0 "$MCC_PID" 2>/dev/null; then
if grep -Fq "Server was successfully joined" "$MCC_LOG" 2>/dev/null; then
echo " MCC connected successfully!"
else
echo " MCC started (check $MCC_LOG for status)"
fi
else
echo " MCC exited unexpectedly. Check $MCC_LOG"
exit 1
fi
echo ""
echo " Send commands: echo 'debug state' >> $INPUT_FILE"
echo " Tail log: tail -f $MCC_LOG"
echo " Stop MCC: echo 'quit' >> $INPUT_FILE"
echo " Stop server: mc-stop $VERSION"
echo ""
else
# Interactive classic mode: run in tmux (no pipe — ConsoleInteractive also needs tty)
tmux kill-session -t mcc-debug 2>/dev/null || true
tmux new-session -d -s mcc-debug -x 160 -y 50 \
"cd '$REPO_ROOT' && dotnet run --project MinecraftClient -c Release --no-build -- ${MCC_ARGS[*]}; echo '=== MCC EXITED ==='; sleep 600"
echo ""
echo " Classic mode started in tmux session 'mcc-debug'"
echo ""
echo " Attach: tmux attach -t mcc-debug"
echo " Detach: Ctrl+B, D"
echo " Kill MCC: tmux kill-session -t mcc-debug"
echo " Note: Use MCC's built-in /debug command or enable LogToFile for log output"
echo ""
fi
echo "Quick commands:"
echo " mc-rcon 'op CursorBot' # Give operator"
echo " mc-rcon 'gamemode creative' # Creative mode"
echo " mc-stop $VERSION # Stop server"