Module: RubyCoded::Plugins::CommandCompletion::StateExtension
- Defined in:
- lib/ruby_coded/plugins/command_completion/state_extension.rb
Overview
Mixed into Chat::State to add command-completion tracking.
Constant Summary collapse
- COMMAND_INFO =
{ "/help" => "Show help message", "/model" => "Select or switch model", "/clear" => "Clear conversation history", "/history" => "Show conversation summary", "/tokens" => "Show detailed token usage and cost", "/agent" => "Toggle agent mode (on/off)", "/plan" => "Toggle plan mode (on/off/save)", "/login" => "Authenticate with an AI provider", "/exit" => "Exit the chat", "/quit" => "Exit the chat" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #accept_command_completion! ⇒ Object
- #command_completion_active? ⇒ Boolean
- #command_completion_down ⇒ Object
- #command_completion_up ⇒ Object
-
#command_suggestions ⇒ Object
Returns an array of [command, description] pairs matching the current input buffer prefix.
- #current_command_suggestion ⇒ Object
- #init_command_completion ⇒ Object
-
#reset_command_completion_index ⇒ Object
Reset index when the buffer changes so selection stays coherent.
Class Method Details
.included(base) ⇒ Object
21 22 23 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 21 def self.included(base) base.attr_reader :command_completion_index end |
Instance Method Details
#accept_command_completion! ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 65 def accept_command_completion! suggestion = current_command_suggestion return unless suggestion cmd, = suggestion @input_buffer.clear @input_buffer << cmd @cursor_position = @input_buffer.length @command_completion_index = 0 end |
#command_completion_active? ⇒ Boolean
29 30 31 32 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 29 def command_completion_active? buf = @input_buffer buf.start_with?("/") && !buf.include?(" ") && !command_suggestions.empty? end |
#command_completion_down ⇒ Object
58 59 60 61 62 63 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 58 def command_completion_down suggestions = command_suggestions return if suggestions.empty? @command_completion_index = (@command_completion_index + 1) % suggestions.size end |
#command_completion_up ⇒ Object
51 52 53 54 55 56 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 51 def command_completion_up suggestions = command_suggestions return if suggestions.empty? @command_completion_index = (@command_completion_index - 1) % suggestions.size end |
#command_suggestions ⇒ Object
Returns an array of [command, description] pairs matching the current input buffer prefix.
36 37 38 39 40 41 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 36 def command_suggestions prefix = @input_buffer.downcase all_descriptions = merged_command_descriptions all_descriptions.select { |cmd, _| cmd.start_with?(prefix) } .sort_by { |cmd, _| cmd } end |
#current_command_suggestion ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 43 def current_command_suggestion suggestions = command_suggestions return nil if suggestions.empty? idx = @command_completion_index % suggestions.size suggestions[idx] end |
#init_command_completion ⇒ Object
25 26 27 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 25 def init_command_completion @command_completion_index = 0 end |
#reset_command_completion_index ⇒ Object
Reset index when the buffer changes so selection stays coherent.
77 78 79 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 77 def reset_command_completion_index @command_completion_index = 0 end |