Module: OllamaAgent::SlashCompletion

Defined in:
lib/ollama_agent/tui_slash_reader.rb

Overview

Longest shared prefix for tab completion (readline-style).

Class Method Summary collapse

Class Method Details

.longest_common_prefix(strings) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity – straightforward index scan



12
13
14
15
16
17
18
19
20
# File 'lib/ollama_agent/tui_slash_reader.rb', line 12

def longest_common_prefix(strings)
  arr = Array(strings).map(&:to_s).reject(&:empty?)
  return "" if arr.empty?

  first = arr.first
  i = 0
  i += 1 while i < first.length && arr.all? { |s| i < s.length && s[i] == first[i] }
  first[0, i]
end