Class: OllamaAgent::RuntimeCommandSystem::Input::Buffer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_posObject (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

#textObject (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

#backspaceObject



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

Returns:

  • (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