cani 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/cani.rb +16 -15
- data/lib/cani/api.rb +9 -0
- data/lib/cani/api/feature.rb +8 -7
- data/lib/cani/fzf.rb +13 -10
- data/lib/cani/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d2b242538b6ab9ffed230b58d02a7e8ce24eb0485f5c8360a3275da7d72c3e99
         | 
| 4 | 
            +
              data.tar.gz: d623b2ea9fd17610916c4c17b2d4f52dd49d1fc7fd51c938969bcc3c4e4b7792
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e4d4ebcced02abe4ed0d85152221fa93a1628ffac9549afbd1f0de16839dce2c353490c92d4874a93cbf5f23d364c44e5acde27254a6a7941313996280c412eb
         | 
| 7 | 
            +
              data.tar.gz: 3bdf7ce824afbc541ff5cd03ab815d29503b750551f1c08c3980eb645bdb0f72612a717f26baebce2b076ae4461dab51370e177c452a48cdf944874616d5d28f
         | 
    
        data/README.md
    CHANGED
    
    | @@ -8,6 +8,14 @@ This wrapper aims to be easy to use out of the box. To achieve this it ships wit | |
| 8 8 | 
             
            for `bash`, `fish`, and `zsh`. [Caniuse data (1.7MB)](https://github.com/Fyrd/caniuse/blob/master/data.json) is fetched and updated automatically
         | 
| 9 9 | 
             
            on a regular interval together with completions.
         | 
| 10 10 |  | 
| 11 | 
            +
            ## Latest changes
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ### 06-10-2018 VERSION 0.5.4
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            - Fixed issue where `system` prints the version of fzf before running the command.
         | 
| 16 | 
            +
            - When multiple matches are found for a given query: `cani use shadow`, an fzf window will
         | 
| 17 | 
            +
              now be opened with results filtered by the text `shadow` as initial query string.
         | 
| 18 | 
            +
             | 
| 11 19 | 
             
            ## Installation
         | 
| 12 20 |  | 
| 13 21 | 
             
            Add this line to your application's Gemfile:
         | 
    
        data/lib/cani.rb
    CHANGED
    
    | @@ -53,10 +53,10 @@ module Cani | |
| 53 53 | 
             
                puts 'table as seen on caniuse.com using curses.'.light_black
         | 
| 54 54 | 
             
                puts ''
         | 
| 55 55 | 
             
                puts 'cani is dependent on fzf (https://github.com/junegunn/fzf) for the interactive TUI to work.'.light_black
         | 
| 56 | 
            -
                puts 'without fzf, commands can still be piped to get the regular (colorless) output'.light_black
         | 
| 56 | 
            +
                puts 'without fzf, commands can still be piped to get the regular (colorless) output.'.light_black
         | 
| 57 57 | 
             
                puts ''
         | 
| 58 58 | 
             
                puts 'Cani requires at least 20 lines and 40 cols to work properly, this is not a hard limit but'.light_black
         | 
| 59 | 
            -
                puts 'below this width, long lines could wrap a lot and reduce visible information.'.light_black
         | 
| 59 | 
            +
                puts 'below this width, long lines could wrap a lot and significantly reduce visible information.'.light_black
         | 
| 60 60 | 
             
                puts ''
         | 
| 61 61 | 
             
                puts 'Usage:'.red
         | 
| 62 62 | 
             
                puts '   cani'.yellow + ' [COMMAND [ARGUMENTS]]'
         | 
| @@ -115,21 +115,22 @@ module Cani | |
| 115 115 |  | 
| 116 116 | 
             
              def self.use(feature = nil)
         | 
| 117 117 | 
             
                @use_min_depth ||= feature ? 1 : 0
         | 
| 118 | 
            +
                can_go_back      = !(config.nav_type?('forward') && @use_min_depth > 0)
         | 
| 119 | 
            +
                matches          = api.find_features feature
         | 
| 118 120 |  | 
| 119 | 
            -
                if  | 
| 121 | 
            +
                return use if can_go_back && matches.empty?
         | 
| 122 | 
            +
                return Api::Feature::Viewer.new(matches.first).render if matches.count == 1
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                chosen = Fzf.pick Fzf.feature_rows, query: feature,
         | 
| 125 | 
            +
                                      header: 'use]   [' + Api::Feature.support_legend,
         | 
| 126 | 
            +
                                      colors: %i[green light_black light_white light_black]
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                # chosen[2] is the title column of a row returned by Fzf.feature_rows
         | 
| 129 | 
            +
                if chosen && chosen.any? && (feature = api.find_feature(chosen[2]))
         | 
| 120 130 | 
             
                  Api::Feature::Viewer.new(feature).render
         | 
| 121 | 
            -
                  use | 
| 122 | 
            -
                 | 
| 123 | 
            -
             | 
| 124 | 
            -
                                         colors: %i[green light_black light_white light_black]))
         | 
| 125 | 
            -
             | 
| 126 | 
            -
                  # chosen[2] is the index of the title column from Fzf.feature_rows
         | 
| 127 | 
            -
                  if chosen.any? && (feature = api.find_feature(chosen[2]))
         | 
| 128 | 
            -
                    Api::Feature::Viewer.new(feature).render
         | 
| 129 | 
            -
                    use
         | 
| 130 | 
            -
                  else
         | 
| 131 | 
            -
                    exit
         | 
| 132 | 
            -
                  end
         | 
| 131 | 
            +
                  use
         | 
| 132 | 
            +
                else
         | 
| 133 | 
            +
                  exit 0
         | 
| 133 134 | 
             
                end
         | 
| 134 135 | 
             
              end
         | 
| 135 136 |  | 
    
        data/lib/cani/api.rb
    CHANGED
    
    | @@ -62,6 +62,15 @@ module Cani | |
| 62 62 | 
             
                  features[idx] if idx
         | 
| 63 63 | 
             
                end
         | 
| 64 64 |  | 
| 65 | 
            +
                def find_features(name)
         | 
| 66 | 
            +
                  name = Regexp.new name.to_s.downcase.gsub(/(\W)/, '.*'), :i
         | 
| 67 | 
            +
                  features.select do |ft|
         | 
| 68 | 
            +
                    ft.title.downcase.match(name) ||
         | 
| 69 | 
            +
                    ft.name.downcase.match(name)  ||
         | 
| 70 | 
            +
                    ft.description.downcase.match(name)
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 65 74 | 
             
                def find_browser(name)
         | 
| 66 75 | 
             
                  name = name.to_s.downcase
         | 
| 67 76 | 
             
                  idx  = browsers.find_index do |bwsr|
         | 
    
        data/lib/cani/api/feature.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            module Cani
         | 
| 2 2 | 
             
              class Api
         | 
| 3 3 | 
             
                class Feature
         | 
| 4 | 
            -
                  attr_reader :title, :status, :spec, :stats, :percent, :name, :browser_note_nums, :notes, :notes_by_num
         | 
| 4 | 
            +
                  attr_reader :title, :status, :spec, :stats, :percent, :name, :browser_note_nums, :notes, :notes_by_num, :description
         | 
| 5 5 |  | 
| 6 6 | 
             
                  STATUSES = {
         | 
| 7 7 | 
             
                    'rec'   => 'rc',
         | 
| @@ -20,12 +20,13 @@ module Cani | |
| 20 20 | 
             
                  }.freeze
         | 
| 21 21 |  | 
| 22 22 | 
             
                  def initialize(attributes = {})
         | 
| 23 | 
            -
                    @name | 
| 24 | 
            -
                    @title | 
| 25 | 
            -
                    @ | 
| 26 | 
            -
                    @ | 
| 27 | 
            -
                    @ | 
| 28 | 
            -
                    @ | 
| 23 | 
            +
                    @name         = attributes[:name].to_s.downcase
         | 
| 24 | 
            +
                    @title        = attributes['title']
         | 
| 25 | 
            +
                    @description  = attributes['description']
         | 
| 26 | 
            +
                    @status       = STATUSES.fetch attributes['status'], attributes['status']
         | 
| 27 | 
            +
                    @spec         = attributes['spec']
         | 
| 28 | 
            +
                    @percent      = attributes['usage_perc_y']
         | 
| 29 | 
            +
                    @notes        = attributes['notes'].split "\n"
         | 
| 29 30 | 
             
                    @notes_by_num = attributes['notes_by_num']
         | 
| 30 31 | 
             
                    @stats, @browser_note_nums = attributes['stats'].each_with_object([{}, {}]) do |(browser, info), (stts, notes)|
         | 
| 31 32 | 
             
                      stts[browser], notes[browser] = info.each_with_object([{}, {}]) do |(version, stat), (st, nt)|
         | 
    
        data/lib/cani/fzf.rb
    CHANGED
    
    | @@ -9,10 +9,11 @@ module Cani | |
| 9 9 |  | 
| 10 10 | 
             
                    rows   = tableize_rows(rows, **opts).join "\n"
         | 
| 11 11 | 
             
                    ohdr   = opts.fetch :header, []
         | 
| 12 | 
            +
                    query  = "--query=\"#{opts[:query]}\"" if opts[:query]
         | 
| 12 13 | 
             
                    header = ohdr.is_a?(Array) ? [:cani, *ohdr].map { |v| v.to_s.downcase }.join(':')
         | 
| 13 14 | 
             
                                               : 'cani:' + ohdr.to_s
         | 
| 14 15 |  | 
| 15 | 
            -
                    `echo "#{rows}" | fzf --ansi --header="[#{header}]"`.split '   '
         | 
| 16 | 
            +
                    `echo "#{rows}" | fzf --ansi --header="[#{header}]" #{query}`.split '   '
         | 
| 16 17 | 
             
                  else
         | 
| 17 18 | 
             
                    # when output of any initial command is being piped
         | 
| 18 19 | 
             
                    # print results and exit this command.
         | 
| @@ -22,19 +23,21 @@ module Cani | |
| 22 23 | 
             
                end
         | 
| 23 24 |  | 
| 24 25 | 
             
                def self.executable?
         | 
| 25 | 
            -
                  @exe ||=  | 
| 26 | 
            +
                  @exe ||= system 'fzf --version > /dev/null 2>&1'
         | 
| 26 27 | 
             
                end
         | 
| 27 28 |  | 
| 28 29 | 
             
                def self.feature_rows
         | 
| 29 | 
            -
                  @feature_rows ||= Cani.api.features.map | 
| 30 | 
            -
             | 
| 31 | 
            -
                    cl = {'un' => :yellow, 'ot' => :magenta}.fetch ft.status, :green
         | 
| 32 | 
            -
                    tt = format('%-24s', ft.title.size > 24 ? ft.title[0..23].strip + '..'
         | 
| 33 | 
            -
                                                            : ft.title)
         | 
| 30 | 
            +
                  @feature_rows ||= Cani.api.features.map(&Fzf.method(:to_feature_row))
         | 
| 31 | 
            +
                end
         | 
| 34 32 |  | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
                   | 
| 33 | 
            +
                def self.to_feature_row(ft)
         | 
| 34 | 
            +
                  pc = format('%.2f%%', ft.percent).rjust 6
         | 
| 35 | 
            +
                  cl = {'un' => :yellow, 'ot' => :magenta}.fetch ft.status, :green
         | 
| 36 | 
            +
                  tt = format('%-24s', ft.title.size > 24 ? ft.title[0..23].strip + '..'
         | 
| 37 | 
            +
                                                          : ft.title)
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  [{content: "[#{ft.status}]", color: cl}, pc,
         | 
| 40 | 
            +
                   {content: tt, color: :default}, *ft.current_support]
         | 
| 38 41 | 
             
                end
         | 
| 39 42 |  | 
| 40 43 | 
             
                def self.browser_rows
         | 
    
        data/lib/cani/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: cani
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.5. | 
| 4 | 
            +
              version: 0.5.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sidney Liebrand
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018-10- | 
| 11 | 
            +
            date: 2018-10-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: colorize
         |