cani 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 056dad5365e1fa79e23f2f0d0402a1410b7d8719f1521caa1288a60c99bbc8a6
4
- data.tar.gz: ab5199feb69612e152dadea893c8a721149c8c9bdf708df4b4b143a91896a93d
3
+ metadata.gz: d2b242538b6ab9ffed230b58d02a7e8ce24eb0485f5c8360a3275da7d72c3e99
4
+ data.tar.gz: d623b2ea9fd17610916c4c17b2d4f52dd49d1fc7fd51c938969bcc3c4e4b7792
5
5
  SHA512:
6
- metadata.gz: e940dca2ceffabead9d8f73c6efece1244a1fbbd6c67ee27a5d81e084b295ce9ac71f1b988da08b647b0325bbc3eb481859c1444883c0334e35f123124ec171c
7
- data.tar.gz: 5b1f9e0f8655b6a8040546e0a41c262cbf73501f86041b6367ecd87a11095f622bf57ee4246748b071bf0dc181ffd788cbab133a7a04d42c997d1d6263a06e33
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 feature && (feature = api.find_feature(feature))
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 unless config.nav_type?('forward') && @use_min_depth > 0
122
- elsif (chosen = Fzf.pick(Fzf.feature_rows,
123
- header: 'use] [' + Api::Feature.support_legend,
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|
@@ -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 = attributes[:name].to_s.downcase
24
- @title = attributes['title']
25
- @status = STATUSES.fetch attributes['status'], attributes['status']
26
- @spec = attributes['spec']
27
- @percent = attributes['usage_perc_y']
28
- @notes = attributes['notes'].split "\n"
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 ||= !system('fzf --version').nil?
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 do |ft|
30
- pc = format('%.2f%%', ft.percent).rjust 6
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
- [{content: "[#{ft.status}]", color: cl}, pc,
36
- {content: tt, color: :default}, *ft.current_support]
37
- end
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
@@ -1,3 +1,3 @@
1
1
  module Cani
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
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.3
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-03 00:00:00.000000000 Z
11
+ date: 2018-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize