Skip to content

Add TUI functionality with --tui parameter for interactive Wordle gameplay#1

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-91573df5-98b0-4641-9a9b-6ee0cc2ee9b9
Draft

Add TUI functionality with --tui parameter for interactive Wordle gameplay#1
Copilot wants to merge 4 commits intomainfrom
copilot/fix-91573df5-98b0-4641-9a9b-6ee0cc2ee9b9

Conversation

Copy link
Copy Markdown

Copilot AI commented Aug 28, 2025

This PR implements a comprehensive TUI (Terminal User Interface) mode for the Wordle game, adding modern interactive gameplay while preserving all existing functionality.

Overview

The new --tui parameter enables a full-screen terminal interface built with ratatui and crossterm, providing an enhanced user experience compared to the traditional CLI mode.

TUI Demo

Key Features

TUI Interface Components

  • Input Area: Displays current attempt number (第X/6次猜测) and live typing
  • Keyboard Area: Real-time QWERTY keyboard layout with color-coded letter status
  • Guess History: Shows all previous attempts with colored feedback
  • Message Area: Game status, instructions, and error messages

Interactive Controls

  • Letter keys: Type your 5-letter guess (automatically converted to uppercase)
  • Enter: Submit guess when 5 letters are entered
  • Backspace: Delete the last typed letter
  • ESC: Exit the game

Color Feedback System

  • Green: Letter is in the correct position
  • Yellow: Letter is in the word but wrong position
  • Red: Letter is not in the word
  • Gray: Letter hasn't been guessed yet

Technical Implementation

New Dependencies

Added ratatui (v0.28) and crossterm (v0.28) for terminal UI and cross-platform terminal control.

Code Structure

  • src/tui.rs: Complete TUI implementation with app state management and rendering
  • src/args.rs: Added --tui command line parameter with conflict validation
  • src/main.rs: Integrated TUI mode with minimal changes to existing logic
  • Cargo.toml: Added required dependencies

Parameter Validation

The --tui parameter conflicts with --random mode as specified in requirements, with clear error messaging.

Compatibility

All existing features work seamlessly with TUI mode:

  • Hard Mode (--difficult): Enforces all constraints in TUI
  • Statistics (--stats): Records and displays game results
  • Config Files (--config): All configuration options supported
  • Custom Word Sets (--final-set, --acceptable-set): Works with TUI
  • CLI Mode: Original functionality completely preserved
  • All Parameters: Day, seed, state file, etc. all functional

Usage Examples

# Basic TUI mode
cargo run -- --tui --word HELLO

# TUI with hard mode
cargo run -- --tui --word HELLO --difficult

# TUI with statistics
cargo run -- --tui --word HELLO --stats

# TUI with custom word sets
cargo run -- --tui -f finals.txt -a acceptables.txt

# Parameter conflict (shows error)
cargo run -- --tui --random  # Error: TUI mode incompatible with random mode

Design Principles

  • Non-Breaking: Zero changes to existing CLI functionality
  • Minimal Impact: New code isolated in tui.rs module
  • Feature Parity: All game logic and features preserved
  • Error Handling: Comprehensive validation and user feedback
  • Performance: Efficient rendering and input handling

The TUI mode provides a modern, interactive experience while maintaining 100% backward compatibility with the existing CLI interface.

This pull request was created as a result of the following prompt from Copilot chat.

在保持我代码原有功能不变的基础上新增一个TUI功能,具体要求如下:

功能要求

  1. 添加 --tui 命令行参数,启用TUI模式
  2. TUI界面需要包含:
    • 输入区域:显示当前输入和进度
    • 键盘区域:实时显示键盘状态,用颜色标识字母状态
    • 猜测历史:显示所有已猜测的单词和反馈
    • 消息区域:显示游戏状态和提示信息
  3. 支持键盘输入:
    • 字母键输入
    • 回车键确认
    • 退格键删除
    • ESC键退出
  4. 颜色反馈:绿色=正确位置,黄色=错误位置,红色=不存在
  5. 保持与所有现有功能的兼容性(困难模式、统计、配置文件等)

技术实现

  1. 添加 ratatui 和 crossterm 依赖
  2. 创建新的 tui.rs 模块
  3. 更新 args.rs 添加 --tui 参数
  4. 在 main.rs 中集成TUI模式
  5. TUI模式不支持随机模式(参数冲突检查)

注意事项

  • 必须保持原有所有功能不变
  • TUI不能代替原来的交互模式
  • 需要在Linux下正常工作
  • 确保代码质量和错误处理

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits August 28, 2025 02:26
Co-authored-by: front-rear <146909790+front-rear@users.noreply.github.com>
Co-authored-by: front-rear <146909790+front-rear@users.noreply.github.com>
Co-authored-by: front-rear <146909790+front-rear@users.noreply.github.com>
Copilot AI changed the title [WIP] Add TUI (Text User Interface) functionality Add TUI functionality with --tui parameter for interactive Wordle gameplay Aug 28, 2025
Copilot AI requested a review from front-rear August 28, 2025 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants