Class: Rufio::CommandModeUI
- Inherits:
-
Object
- Object
- Rufio::CommandModeUI
- Defined in:
- lib/rufio/command_mode_ui.rb
Overview
コマンドモードのUI - Tab補完とフローティングウィンドウでの結果表示
Instance Method Summary collapse
-
#autocomplete(input) ⇒ Array<String>
入力文字列に対する補完候補を取得.
-
#clear_prompt ⇒ Object
コマンド入力プロンプトをクリア.
-
#complete_command(input) ⇒ String
コマンドを補完する.
-
#initialize(command_mode, dialog_renderer) ⇒ CommandModeUI
constructor
A new instance of CommandModeUI.
-
#set_terminal_ui(terminal_ui) ⇒ Object
terminal_ui を設定.
-
#show_input_prompt(input, suggestions = []) ⇒ Object
コマンド入力プロンプトをフローティングウィンドウで表示.
-
#show_result(result) ⇒ Object
コマンド実行結果をフローティングウィンドウで表示.
Constructor Details
#initialize(command_mode, dialog_renderer) ⇒ CommandModeUI
Returns a new instance of CommandModeUI.
8 9 10 11 12 13 14 |
# File 'lib/rufio/command_mode_ui.rb', line 8 def initialize(command_mode, dialog_renderer) @command_mode = command_mode @dialog_renderer = dialog_renderer @terminal_ui = nil # 最後に表示したウィンドウの位置とサイズを保存 @last_window = nil end |
Instance Method Details
#autocomplete(input) ⇒ Array<String>
入力文字列に対する補完候補を取得
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rufio/command_mode_ui.rb', line 24 def autocomplete(input) # 利用可能なコマンド一覧を取得 available = @command_mode.available_commands.map(&:to_s) # 入力が空の場合は全てのコマンドを返す return available if input.empty? # 入力に一致するコマンドをフィルタリング available.select { |cmd| cmd.start_with?(input) } end |
#clear_prompt ⇒ Object
コマンド入力プロンプトをクリア
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rufio/command_mode_ui.rb', line 144 def clear_prompt return unless @last_window @dialog_renderer.clear_area( @last_window[:x], @last_window[:y], @last_window[:width], @last_window[:height] ) @last_window = nil end |
#complete_command(input) ⇒ String
コマンドを補完する
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rufio/command_mode_ui.rb', line 38 def complete_command(input) suggestions = autocomplete(input) # マッチするものがない場合は元の入力を返す return input if suggestions.empty? # 一つだけマッチする場合はそれを返す return suggestions.first if suggestions.length == 1 # 複数マッチする場合は共通プレフィックスを返す find_common_prefix(suggestions) end |
#set_terminal_ui(terminal_ui) ⇒ Object
terminal_ui を設定
17 18 19 |
# File 'lib/rufio/command_mode_ui.rb', line 17 def set_terminal_ui(terminal_ui) @terminal_ui = terminal_ui end |
#show_input_prompt(input, suggestions = []) ⇒ Object
コマンド入力プロンプトをフローティングウィンドウで表示
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rufio/command_mode_ui.rb', line 54 def show_input_prompt(input, suggestions = []) # タイトル title = "Command Mode" # Build content lines content_lines = [""] content_lines << "#{input}_" # Show cursor as _ content_lines << "" content_lines << "Tab: Complete | Enter: Execute | ESC: Cancel" # ウィンドウの色設定(青) border_color = "\e[34m" # Blue title_color = "\e[1;34m" # Bold blue content_color = "\e[37m" # White # ウィンドウサイズを計算 width, height = @dialog_renderer.calculate_dimensions(content_lines, { title: title, min_width: 50, max_width: 80 }) # 中央位置を計算 x, y = @dialog_renderer.calculate_center(width, height) # ウィンドウの位置とサイズを保存 @last_window = { x: x, y: y, width: width, height: height } # フローティングウィンドウを描画 @dialog_renderer.draw_floating_window(x, y, width, height, title, content_lines, { border_color: border_color, title_color: title_color, content_color: content_color }) end |
#show_result(result) ⇒ Object
コマンド実行結果をフローティングウィンドウで表示
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rufio/command_mode_ui.rb', line 92 def show_result(result) # nil または空文字列の場合は何も表示しない return if result.nil? || result.empty? # Hash形式の結果を処理 if result.is_a?(Hash) result_text = format_hash_result(result) is_error = !result[:success] else # 文字列形式の結果(従来の動作) result_text = result is_error = result.include?("⚠️") || result.include?("Error") end # 結果を行に分割 result_lines = result_text.split("\n") # ウィンドウの色設定 if is_error border_color = "\e[31m" # Red title_color = "\e[1;31m" # Bold red content_color = "\e[37m" # White else border_color = "\e[32m" # Green title_color = "\e[1;32m" # Bold green content_color = "\e[37m" # White end # ウィンドウタイトル title = "Command Result" # コンテンツ行を構築 content_lines = [""] + result_lines + ["", "Press any key to close"] # ウィンドウサイズを計算 width, height = @dialog_renderer.calculate_dimensions(content_lines, { title: title, min_width: 40, max_width: 100 }) # オーバーレイダイアログを表示 (title, content_lines, { width: width, height: height, border_color: border_color, title_color: title_color, content_color: content_color }) end |