Sha256: 0041054ca5ad56045003b46663f5ba830c67edcad8fc1a17804822c818b7a591
Contents?: true
Size: 865 Bytes
Versions: 4
Compression:
Stored size: 865 Bytes
Contents
require 'amatch' require 'search_ui' require 'term/ansicolor' module Ollama::Utils::Chooser include SearchUI include Term::ANSIColor module_function 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 ? "#{blue{?⮕}} #{on_blue{m}}" : " #{m}" } * ?\n }, found: -> _answer, matches, selector { matches[selector] }, output: STDOUT ).start return entry if entry end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
ollama-ruby-0.6.0 | lib/ollama/utils/chooser.rb |
ollama-ruby-0.5.0 | lib/ollama/utils/chooser.rb |
ollama-ruby-0.4.0 | lib/ollama/utils/chooser.rb |
ollama-ruby-0.3.2 | lib/ollama/utils/chooser.rb |