9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/ollama/utils/chooser.rb', line 9
def choose(entries)
entry = Search.new(
match: -> answer {
matcher = Amatch::PairDistance.new(answer.downcase)
matches = entries.map { |n| [ n, -matcher.similar(n.to_s.downcase) ] }.
select { |_, s| s < 0 }.sort_by(&:last).map(&:first)
matches.empty? and matches = entries
matches.first(Tins::Terminal.lines - 1)
},
query: -> _answer, matches, selector {
matches.each_with_index.map { |m, i|
i == selector ? "#{Term::ANSIColor.blue{?⮕}} #{m.on_blue}" : " #{m}"
} * ?\n
},
found: -> _answer, matches, selector {
matches[selector]
},
output: STDOUT
).start
return entry if entry
end
|