Sha256: f7e03fac181f19a394e3d4e544aba111b94229caa3d93ab8c5bacb9f48ac0be8

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'ver/vendor/fuzzy_file_finder'

module VER
  class View::List::FuzzyFileFinder < View::List
    FFF = ::FuzzyFileFinder

    def fffinder
      @fffinder ||= FFF.new(Dir.pwd)
    rescue FFF::TooManyEntries
      message "The FuzzyFileFinder is overwhelmed by the amount of files"
      destroy
    end

    def update
      choices = fffinder.find(entry.value.chomp('/'))
      choices = choices.sort_by{|m| [-m[:score], m[:path]] }

      list.clear

      pwd = Dir.pwd + '/'
      choices.each do |choice|
        choice[:path].sub!(pwd, '')
        insert_choice(choice)
      end
    end

    def insert_choice(choice)
      path, score = choice.values_at(:path, :score)
      list.insert(:end, path)

      foreground, background =
        case score
        when 0          ; ['white',  'black']
        when 0   ..0.25 ; ['red',    'black']
        when 0.25..0.75 ; ['yellow', 'black']
        when 0.75..1    ; ['green',  'black']
        end

      list.itemconfigure(:end,
              foreground: foreground,       background: background,
        selectforeground: background, selectbackground: foreground)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ver-2009.12.14 lib/ver/view/list/fuzzy_file_finder.rb
ver-2009.11.29 lib/ver/view/list/fuzzy_file_finder.rb
ver-2009.11.28 lib/ver/view/list/fuzzy_file_finder.rb
ver-2009.10.14 lib/ver/view/list/fuzzy_file_finder.rb