ifilter 0.0.7 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 785b1a55881274c8540597c38a0f2a721f283760
4
- data.tar.gz: 8ceb304314af687f91f1ec464e1f0352b081bbe4
3
+ metadata.gz: b3c3826565d691dd1f2125b61351f67e7328599d
4
+ data.tar.gz: f98fc31feb76580b6b696b7ccc76a6eee7902eb2
5
5
  SHA512:
6
- metadata.gz: a7be243c9ca4a2f18b91f4724de580cb731f099253abeab4964ef3ef2a97dcc99fab23fb74eeb46303d9d2f7a86dfbbbdbb2f6e2c999a331e93d4df011d683e7
7
- data.tar.gz: 89597c557f58eb73841e8df3538a233735931ab1618a9e7bc4fe009c512b400be3d0fb9356204822cc9a8f40a326a48422fae53229165fd452971a3a35ad8fb0
6
+ metadata.gz: 300473b6da810bc1c060924881e2ecc3bd3e49293eb51c35449aafc32e1e41fc397033f97bd5be826b75be72e3b3af2d8523448ab2922cf5c600e418d37d9cac
7
+ data.tar.gz: a9809b2d05043a1f6f0bf82b1233d3f091af9fb2f0d079cc64a84b8b22ac7192b531b748e681f4a051aa865bda180de99c39dadb2d553aa414993539a7ea87be
data/.gitignore CHANGED
@@ -7,8 +7,3 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
@@ -1,22 +1,21 @@
1
- Copyright (c) 2014 kaihar4
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2015 kaihar4
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -16,11 +16,13 @@ Add this line to your application's Gemfile:
16
16
  gem 'ifilter'
17
17
  ```
18
18
 
19
+ And then execute:
20
+
21
+ $ bundle
22
+
19
23
  Or install it yourself as:
20
24
 
21
- ```sh
22
- $ gem install ifilter
23
- ```
25
+ $ gem install ifilter
24
26
 
25
27
  ## Usage
26
28
 
@@ -30,7 +32,7 @@ $ gem install ifilter
30
32
  $ ps aux | ifilter
31
33
  ```
32
34
 
33
- ![execute](https://raw.github.com/wiki/kaihar4/ifilter/images/execute.gif)
35
+ ![execute](http://kaihar4.com/images/github.com/kaihar4/ifilter/execute.gif)
34
36
 
35
37
  ### Module Style
36
38
 
@@ -42,4 +44,18 @@ array = ['foo', 'bar', 'hoge', 'fuga']
42
44
  puts Ifilter.filtering(array)
43
45
  ```
44
46
 
45
- ![module](https://raw.github.com/wiki/kaihar4/ifilter/images/module.gif)
47
+ ![module](http://kaihar4.com/images/github.com/kaihar4/ifilter/module.gif)
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/kaihar4/ifilter/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ifilter'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --path vendor/bundle
File without changes
@@ -1,4 +1,5 @@
1
- $LOAD_PATH << File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
3
  require 'ifilter/version'
3
4
 
4
5
  Gem::Specification.new do |spec|
@@ -6,19 +7,21 @@ Gem::Specification.new do |spec|
6
7
  spec.version = Ifilter::VERSION
7
8
  spec.authors = ['kaihar4']
8
9
  spec.email = ['kaihar4@gmail.com']
9
- spec.summary = 'Interactive Filter.'
10
+ spec.summary = 'Interactive Filter'
10
11
  spec.description = spec.summary
11
12
  spec.homepage = 'https://github.com/kaihar4/ifilter'
12
13
  spec.license = 'MIT'
13
14
 
14
- spec.files = `git ls-files -z`.split("\x0")
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
17
18
  spec.require_paths = ['lib']
18
19
 
19
20
  spec.add_runtime_dependency 'curses'
20
21
  spec.add_runtime_dependency 'safe_colorize'
21
22
 
22
- spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'bundler', '~> 1.9'
23
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'awesome_print'
24
27
  end
@@ -1,9 +1,10 @@
1
- require 'ifilter/interface'
1
+ require 'ifilter/window'
2
+ require 'ifilter/client'
2
3
  require 'ifilter/input'
3
4
 
4
5
  module Ifilter
5
6
  def self.filtering(array)
6
- name = caller.last.match(/([^\/]+?)(\.|:)/)[1].capitalize
7
+ name = caller.last.match(/(?<name>[^\/]+?)(\.|:)/)[:name].capitalize
7
8
 
8
9
  isatty = STDOUT.isatty
9
10
 
@@ -12,7 +13,7 @@ module Ifilter
12
13
  STDOUT.reopen('/dev/tty')
13
14
  end
14
15
 
15
- ifilter = Interface.new(name)
16
+ ifilter = Client.new(name)
16
17
  result = ifilter.grep(array)
17
18
 
18
19
  unless isatty
@@ -1,7 +1,7 @@
1
1
  require 'curses'
2
2
 
3
3
  module Ifilter
4
- class Interface
4
+ class Client
5
5
  def initialize(name)
6
6
  @prompt = "#{name}> "
7
7
  @target = []
@@ -11,11 +11,7 @@ module Ifilter
11
11
  @cursor_position = 1
12
12
  @page_number = 1
13
13
 
14
- Curses.init_screen
15
- Curses.crmode
16
- Curses.noecho
17
- @window = Curses::Window.new(Curses.lines, Curses.cols, 0, 0)
18
- @window.keypad(true)
14
+ @window = Window.new(Curses.lines, Curses.cols, 0, 0)
19
15
  end
20
16
 
21
17
  def grep(array)
@@ -36,11 +32,11 @@ module Ifilter
36
32
  elsif keycode == :KEY_CTRL_J # <CR>
37
33
  break if @outputs.size >= @cursor_position
38
34
 
39
- elsif keycode == :KEY_DOWN
35
+ elsif keycode == :KEY_DOWN || keycode == :KEY_CTRL_N
40
36
  down_cursor_position unless @outputs.empty?
41
37
  next
42
38
 
43
- elsif keycode == :KEY_UP
39
+ elsif keycode == :KEY_UP || keycode == :KEY_CTRL_P
44
40
  up_cursor_position unless @outputs.empty?
45
41
  next
46
42
 
@@ -52,10 +48,10 @@ module Ifilter
52
48
  update_window
53
49
  end
54
50
 
55
- Curses.close_screen
51
+ @window.close
56
52
  @outputs[@cursor_position - 1]
57
53
  rescue Interrupt # <C-c>
58
- Curses.close_screen
54
+ @window.close
59
55
  end
60
56
 
61
57
  private
@@ -81,7 +77,7 @@ module Ifilter
81
77
 
82
78
  def get_keycode(key)
83
79
  Curses.constants.select do |name|
84
- /^KEY/ =~ name && Curses.const_get(name) == key
80
+ name =~ /^KEY/ && Curses.const_get(name) == key
85
81
  end.first
86
82
  end
87
83
 
@@ -89,7 +85,7 @@ module Ifilter
89
85
  array.each_with_object([]).with_index do |(str, outputs), index|
90
86
  next if index < start_index
91
87
 
92
- regex = @input.to_regex
88
+ regex = @input.to_regexp
93
89
 
94
90
  if !regex.nil? && regex =~ str
95
91
  outputs << str
@@ -100,9 +96,20 @@ module Ifilter
100
96
  def output_line(word)
101
97
  unless @cursor_position - 1 > @window.maxy - 1
102
98
  @window.setpos(@cursor_position - 1, 0)
103
- @cursor_position += 1
104
99
 
105
- @window << word
100
+ if !@input.size.zero? && @cursor_position > 1 && match_pos = word =~ @input.to_regexp
101
+ @window << word[0, match_pos]
102
+
103
+ @window.standout
104
+ @window << word[match_pos, @input.size]
105
+ @window.standend
106
+
107
+ @window << word[match_pos + @input.size, word.size - match_pos + @input.size]
108
+ else
109
+ @window << word
110
+ end
111
+
112
+ @cursor_position += 1
106
113
  end
107
114
  end
108
115
 
@@ -22,7 +22,7 @@ module Ifilter
22
22
  @text
23
23
  end
24
24
 
25
- def to_regex
25
+ def to_regexp
26
26
  /#{@text}/i
27
27
  rescue
28
28
  nil
@@ -1,3 +1,3 @@
1
1
  module Ifilter
2
- VERSION = '0.0.7'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'curses'
2
+
3
+ module Ifilter
4
+ class Window < Curses::Window
5
+ def initialize(height, width, y, x)
6
+ Curses.init_screen
7
+ Curses.crmode
8
+ Curses.noecho
9
+
10
+ super
11
+
12
+ self.keypad(true)
13
+ end
14
+
15
+ def close
16
+ Curses.close_screen
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ifilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-11-14 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.7'
47
+ version: '1.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.7'
54
+ version: '1.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,35 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
- description: Interactive Filter.
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Interactive Filter
70
98
  email:
71
99
  - kaihar4@gmail.com
72
100
  executables:
@@ -79,12 +107,15 @@ files:
79
107
  - LICENSE.txt
80
108
  - README.md
81
109
  - Rakefile
82
- - bin/ifilter
110
+ - bin/console
111
+ - bin/setup
112
+ - exe/ifilter
83
113
  - ifilter.gemspec
84
114
  - lib/ifilter.rb
115
+ - lib/ifilter/client.rb
85
116
  - lib/ifilter/input.rb
86
- - lib/ifilter/interface.rb
87
117
  - lib/ifilter/version.rb
118
+ - lib/ifilter/window.rb
88
119
  homepage: https://github.com/kaihar4/ifilter
89
120
  licenses:
90
121
  - MIT
@@ -105,8 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
136
  version: '0'
106
137
  requirements: []
107
138
  rubyforge_project:
108
- rubygems_version: 2.2.2
139
+ rubygems_version: 2.4.5
109
140
  signing_key:
110
141
  specification_version: 4
111
- summary: Interactive Filter.
142
+ summary: Interactive Filter
112
143
  test_files: []