Class: OllamaAgent::RuntimeCommandSystem::Input::Buffer
- Inherits:
-
Object
- Object
- OllamaAgent::RuntimeCommandSystem::Input::Buffer
- Defined in:
- lib/ollama_agent/runtime_command_system/input_buffer.rb
Overview
Minimal mutable edit buffer independent from chat/provider runtimes.
Instance Attribute Summary collapse
-
#cursor_pos ⇒ Object
readonly
Returns the value of attribute cursor_pos.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #accept_ghost_text(ghost) ⇒ Object
- #backspace ⇒ Object
- #command_mode? ⇒ Boolean
-
#initialize(text = "") ⇒ Buffer
constructor
A new instance of Buffer.
- #insert(chars) ⇒ Object
- #move_cursor(delta) ⇒ Object
Constructor Details
#initialize(text = "") ⇒ Buffer
Returns a new instance of Buffer.
10 11 12 13 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 10 def initialize(text = "") @text = text.to_s.dup @cursor_pos = @text.length end |
Instance Attribute Details
#cursor_pos ⇒ Object (readonly)
Returns the value of attribute cursor_pos.
8 9 10 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 8 def cursor_pos @cursor_pos end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
8 9 10 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 8 def text @text end |
Instance Method Details
#accept_ghost_text(ghost) ⇒ Object
32 33 34 35 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 32 def accept_ghost_text(ghost) @text = ghost.full_completion.to_s.dup @cursor_pos = @text.length end |
#backspace ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 21 def backspace return if @cursor_pos.zero? @text = @text[0...(@cursor_pos - 1)] + @text[@cursor_pos..].to_s @cursor_pos -= 1 end |
#command_mode? ⇒ Boolean
37 38 39 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 37 def command_mode? @text.start_with?("/") end |
#insert(chars) ⇒ Object
15 16 17 18 19 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 15 def insert(chars) value = chars.to_s @text = @text[0...@cursor_pos] + value + @text[@cursor_pos..].to_s @cursor_pos += value.length end |
#move_cursor(delta) ⇒ Object
28 29 30 |
# File 'lib/ollama_agent/runtime_command_system/input_buffer.rb', line 28 def move_cursor(delta) @cursor_pos = [[@cursor_pos + delta.to_i, 0].max, @text.length].min end |