Sha256: 2bc9f7e424a9126de0e5dcfe23c4713af2c0ffd0917d72af28177411c5102a87

Contents?: true

Size: 763 Bytes

Versions: 3

Compression:

Stored size: 763 Bytes

Contents

require "tty-prompt"

# Monkeypatch for TTY::Prompt so that we can sanitize the filter value
module TTY
  class Prompt
    class List
      def choices(values = (not_set = true))
        if not_set
          if !filterable? || @filter.empty?
            @choices
          else
            filter_value = sanitize_for_filter(@filter.join)
            @filter_cache[filter_value] ||= @choices.enabled.select do |choice|
              sanitize_for_filter(choice.name.to_s).include?(filter_value)
            end
          end
        else
          @filter_cache = {}
          values.each { |val| @choices << val }
        end
      end

      def sanitize_for_filter(value)
        value
          .downcase
          .gsub(/[-_]/, '')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kuber_kit-1.3.9 lib/kuber_kit/extensions/tty_prompt.rb
kuber_kit-1.3.8 lib/kuber_kit/extensions/tty_prompt.rb
kuber_kit-1.3.7 lib/kuber_kit/extensions/tty_prompt.rb