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)", "/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
20 21 22 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 20 def self.included(base) base.attr_reader :command_completion_index end |
Instance Method Details
#accept_command_completion! ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 64 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
28 29 30 31 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 28 def command_completion_active? buf = @input_buffer buf.start_with?("/") && !buf.include?(" ") && !command_suggestions.empty? end |
#command_completion_down ⇒ Object
57 58 59 60 61 62 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 57 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
50 51 52 53 54 55 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 50 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.
35 36 37 38 39 40 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 35 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
42 43 44 45 46 47 48 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 42 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
24 25 26 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 24 def init_command_completion @command_completion_index = 0 end |
#reset_command_completion_index ⇒ Object
Reset index when the buffer changes so selection stays coherent.
76 77 78 |
# File 'lib/ruby_coded/plugins/command_completion/state_extension.rb', line 76 def reset_command_completion_index @command_completion_index = 0 end |