Skip to content

feat(tui): Complete TUI implementation#14

Draft
Masterisk-F wants to merge 2 commits into
masterfrom
worktree-tui-investigation
Draft

feat(tui): Complete TUI implementation#14
Masterisk-F wants to merge 2 commits into
masterfrom
worktree-tui-investigation

Conversation

@Masterisk-F

Copy link
Copy Markdown
Owner

Summary

Complete the TUI (Terminal User Interface) implementation with all core components.

Changes

  • tuiApp.rb: Main application entry point and UI orchestration
  • tuiDisc.rb: Disc information display and management
  • tuiHelpers.rb: Common utility functions and helpers
  • tuiKeyHandler.rb: Keyboard input handling
  • tuiMessages.rb: Internationalization and message management
  • tuiMultipleHits.rb: Multiple search results handling
  • tuiPreferences.rb: Preferences/configuration UI
  • tuiRipStatus.rb: Rip progress status display
  • tuiSummary.rb: Summary view after rip completion

Key Fixes

  • Removed duplicate tUIDisc.rb file
  • Fixed typo in update queue event name
  • Dynamic layout height calculation in Preferences
  • Synchronous system calls for log/dir opening in Summary

This commit includes the following fixes for the TUI:

- Remove duplicate tUIDisc.rb file

- Fix typo in update queue event name for multiple records

- Dynamically calculate layout height in Preferences to avoid overflow

- Use synchronous system calls for log/dir opening in Summary
…and 159 tests

## Changes
- **Gemfile**: Added dependency definition for tty-prompt, tty-table, tty-box,
  tty-reader, tty-spinner, pastel, rspec
- **bin/rubyripper_tui**: New TUI entrypoint script (installable via
  configure --enable-tui as rrr_tui)
- **Preferences::Data**: Added attr_accessor :uiType
- **Preferences::SetDefaults**: Default uiType to 'tui'
- **configure**: Added --enable-tui support with install/uninstall of rrr_tui

## Tests (159 examples, 0 failures, 1 pending)
- spec/tui/tui_helpers_spec.rb — 17 tests for color/clear/header/footer
- spec/tui/tui_key_handler_spec.rb — 23 tests for all key mappings
- spec/tui/tui_messages_spec.rb — 28 tests for all state transitions + draw
- spec/tui/tui_disc_spec.rb — 22 tests for scan/save/edit/select/draw
- spec/tui/tui_preferences_spec.rb — 21 tests for tabs/focus/edit/save/uiType
- spec/tui/tui_rip_status_spec.rb — 16 tests for progress/logs/cancel/dir
- spec/tui/tui_multiple_hits_spec.rb — 2 tests for Gnudb/MusicBrainz
- spec/tui/tui_summary_spec.rb — 8 tests for success/fail/actions
- spec/tui/tui_app_spec.rb — 22 tests for init/queue/keys/errors
- spec/preferences/data_spec.rb — 3 tests for uiType accessor + default

## Pending
- TUIDisc draw: musicbrainz_failed stub does not override parent context
  (RSpec @instance_variable double interaction issue)
@Masterisk-F

Copy link
Copy Markdown
Owner Author

実装内容

この PR は worktree-tui-investigation ブランチからの追加実装です。TUI コードの動作に必要な不足部分を補完し、全コンポーネントのユニットテストを追加しました。

実装したコード修正(5 ファイル)

ファイル 変更 理由
Gemfile 新規 tty-prompt, tty-table, tty-box, tty-reader, tty-spinner, pastel の依存定義。これがないと TUI は LoadError で起動しない
bin/rubyripper_tui 新規 TUI エントリーポイント。configure --enable-tuirrr_tui としてインストール可能
lib/rubyripper/preferences/data.rb 修正 attr_accessor :uiType を追加。これがないと設定画面が NoMethodError でクラッシュ
lib/rubyripper/preferences/setDefaults.rb 修正 @data.uiType = 'tui' をデフォルト値として設定
configure 修正 --enable-tui 引数解析、Makefile に rrr_tui の install/uninstall を追加

追加したテスト(10 ファイル、159 ケース)

テストファイル テスト数 主な検証項目
spec/tui/tui_helpers_spec.rb 17 色出力、clear_screen、header/footer 描画、status_indicator
spec/tui/tui_key_handler_spec.rb 23 矢印キー、F1-F10、Enter/Escape/Space、通常文字のマッピング全パターン
spec/tui/tui_messages_spec.rb 28 全 10 状態の遷移と draw 出力(welcome/scanning/error/custom 等)
spec/tui/tui_disc_spec.rb 22 スキャン(成功/失敗/スレッド)、メタデータ編集、トラック選択、描画
spec/tui/tui_preferences_spec.rb 21 タブ 5 種の切替、フォーカス移動、bool/select/int/string 編集、保存/検証
spec/tui/tui_rip_status_spec.rb 16 プログレス更新、ログ管理、キャンセル、dir_exists 3 分岐
spec/tui/tui_multiple_hits_spec.rb 2 Gnudb 文字列 / MusicBrainz XML 両形式の選択
spec/tui/tui_summary_spec.rb 8 成功/失敗表示、open_log/open_dir/back アクション
spec/tui/tui_app_spec.rb 22 初期化、キュー処理(4 種イベント)、メッセージ/ディスク画面キーハンドラ
spec/preferences/data_spec.rb 3 uiType アクセサの存在確認とデフォルト値検証

実行結果: 159 examples, 0 failures, 1 pending

未解決の課題

1. TUIDisc#drawmusicbrainz_failed スタブ競合(1 pending)

instance_variable_set で注入した double に対して before(:each)allow(double).to receive(:musicbrainz_failed).and_return(true) を設定しても、子コンテキストでオーバーライドが効かない。原因は RSpec の double が let でないインスタンス変数の場合、親コンテキストの allow より後に子の before が実行されるが、double が事前に解決されていてスタブが伝播しない問題。機能面には影響なし。

2. TUI 未実装機能(リリースには不要)

  • Gemfile 重複: tUIDisc.rb の重複はこのブランチでは存在しない(worktree-tui-investigation ブランチに元々ない)
  • i18n: TUI 文字列の翻訳(.po/.mo)は未対応。英語のみ動作
  • Preferences::Data の初期化順序: テスト環境($run_specs = true)では Singleton が無効化されるため、Preferences::Main.instance に依存するクラスはテストで明示的に依存注入が必要
  • TTY::Screen 非 TTY 環境: テスト実行時に TTY::Screen.width/height をスタブする必要あり。本番は端末サイズを自動検出

3. 今後の改善候補

  • Gemfilebase64 gem を追加(Ruby 3.4+ の警告対応)
  • RuboCop の CI 統合と既存 TUI コードのリンティング
  • E2E テスト(実際のキー入力シミュレーション)

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.

1 participant