ifilter 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +19 -0
- data/Rakefile +2 -0
- data/bin/ifilter +19 -0
- data/ifilter.gemspec +24 -0
- data/lib/ifilter/input.rb +27 -0
- data/lib/ifilter/interface.rb +128 -0
- data/lib/ifilter/version.rb +3 -0
- data/lib/ifilter.rb +26 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8129ac66b6af909e2afc5a47bfa8fe6e563ebbf0
|
4
|
+
data.tar.gz: 5e976e1bcc01f9024a4727d9ca30799e92b6e148
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e22eeb3debb9ab81741b6385f50b444496307946e4491bc99f511741b51041a03a3ac987a96042cd995ae3079f3d6b93cbdc9dcc43f6bb41b82b85cd18a98059
|
7
|
+
data.tar.gz: f0e8d0d50140544fb56a11f53ab3f7e69bc9abc74d408fe26b651fc3f71c71b042f39b0e60c86bae4b88df525845d77ec1591945921bf45977300cf8061cb678
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 kaihar4
|
2
|
+
|
3
|
+
MIT License
|
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:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Ifilter
|
2
|
+
|
3
|
+
Interactive Filter.
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Ifilter provides the interactive filtering.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```sh
|
12
|
+
$ gem install ifilter
|
13
|
+
```
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'ifilter'
|
19
|
+
```
|
data/Rakefile
ADDED
data/bin/ifilter
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'colorize'
|
4
|
+
require 'ifilter'
|
5
|
+
|
6
|
+
using Colorize
|
7
|
+
|
8
|
+
args = []
|
9
|
+
|
10
|
+
isatty = STDIN.isatty
|
11
|
+
|
12
|
+
unless isatty
|
13
|
+
STDIN.each_line do |line|
|
14
|
+
args << line.to_pure.chomp!
|
15
|
+
end
|
16
|
+
STDIN.reopen('/dev/tty')
|
17
|
+
end
|
18
|
+
|
19
|
+
puts Ifilter.filtering(args)
|
data/ifilter.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
2
|
+
require 'ifilter/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'ifilter'
|
6
|
+
spec.version = Ifilter::VERSION
|
7
|
+
spec.authors = ['kaihar4']
|
8
|
+
spec.email = ['kaihar4@gmail.com']
|
9
|
+
spec.summary = 'Interactive Filter.'
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = 'https://github.com/kaihar4/ifilter'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
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)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_runtime_dependency 'colorize'
|
20
|
+
spec.add_runtime_dependency 'curses'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ifilter
|
2
|
+
class Input
|
3
|
+
attr_accessor :text
|
4
|
+
|
5
|
+
def initialize(text = '')
|
6
|
+
@text = text
|
7
|
+
end
|
8
|
+
|
9
|
+
def <<(text)
|
10
|
+
@text << text
|
11
|
+
end
|
12
|
+
|
13
|
+
def backspace!
|
14
|
+
@text.chop!
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
@text
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_regex
|
22
|
+
/#{@text}/
|
23
|
+
rescue
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'curses'
|
2
|
+
|
3
|
+
module Ifilter
|
4
|
+
class Interface
|
5
|
+
def initialize(name, array)
|
6
|
+
@prompt = "#{name}> "
|
7
|
+
@targets = array
|
8
|
+
|
9
|
+
@input = Input.new
|
10
|
+
@outputs = []
|
11
|
+
@cursor_position = 1
|
12
|
+
|
13
|
+
Curses.init_screen
|
14
|
+
Curses.crmode
|
15
|
+
Curses.noecho
|
16
|
+
@window = Curses::Window.new(Curses.lines, Curses.cols, 0, 0)
|
17
|
+
@window.keypad(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def grep
|
21
|
+
output_line(@prompt)
|
22
|
+
output_choises
|
23
|
+
reset_cursor_position
|
24
|
+
|
25
|
+
loop do
|
26
|
+
key = @window.getch
|
27
|
+
keycode = get_keycode(key)
|
28
|
+
|
29
|
+
if key.class == String
|
30
|
+
@input << key
|
31
|
+
|
32
|
+
# <BS>
|
33
|
+
elsif key == 127
|
34
|
+
@input.backspace!
|
35
|
+
|
36
|
+
# <CR>
|
37
|
+
elsif keycode == :KEY_CTRL_J
|
38
|
+
if @outputs.size >= @cursor_position && @cursor_position >= 1
|
39
|
+
break
|
40
|
+
else
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
elsif keycode == :KEY_DOWN
|
45
|
+
down_cursor_position
|
46
|
+
next
|
47
|
+
|
48
|
+
elsif keycode == :KEY_UP
|
49
|
+
up_cursor_position
|
50
|
+
next
|
51
|
+
|
52
|
+
# Ignore other keys
|
53
|
+
else
|
54
|
+
next
|
55
|
+
end
|
56
|
+
|
57
|
+
# Initialize a window
|
58
|
+
@outputs = []
|
59
|
+
@window.clear
|
60
|
+
reset_cursor_position
|
61
|
+
|
62
|
+
output_line(@prompt + @input.to_s)
|
63
|
+
output_choises
|
64
|
+
reset_cursor_position
|
65
|
+
end
|
66
|
+
|
67
|
+
Curses.close_screen
|
68
|
+
@outputs[@cursor_position - 1]
|
69
|
+
|
70
|
+
# <C-c>
|
71
|
+
rescue Interrupt
|
72
|
+
Curses.close_screen
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def get_keycode(key)
|
78
|
+
Curses.constants.select do |name|
|
79
|
+
/^KEY/ =~ name && Curses.const_get(name) == key
|
80
|
+
end.first
|
81
|
+
end
|
82
|
+
|
83
|
+
def output_choises
|
84
|
+
# Filtering
|
85
|
+
@targets.each do |target|
|
86
|
+
regex = @input.to_regex
|
87
|
+
|
88
|
+
if !regex.nil? && regex =~ target
|
89
|
+
@outputs << target
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
@outputs.each { |output| output_line(output) }
|
94
|
+
end
|
95
|
+
|
96
|
+
def output_line(word)
|
97
|
+
@window.setpos(@cursor_position - 1, 0)
|
98
|
+
@cursor_position += 1
|
99
|
+
|
100
|
+
@window << word
|
101
|
+
end
|
102
|
+
|
103
|
+
def up_cursor_position
|
104
|
+
if @cursor_position == 1
|
105
|
+
@window.setpos(@outputs.size, 0)
|
106
|
+
@cursor_position = @outputs.size
|
107
|
+
else
|
108
|
+
@window.setpos(@cursor_position - 1, 0)
|
109
|
+
@cursor_position -= 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def down_cursor_position
|
114
|
+
if @cursor_position == @outputs.size
|
115
|
+
@window.setpos(1, 0)
|
116
|
+
@cursor_position = 1
|
117
|
+
else
|
118
|
+
@window.setpos(@cursor_position + 1, 0)
|
119
|
+
@cursor_position += 1
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def reset_cursor_position
|
124
|
+
@window.setpos(1, 0)
|
125
|
+
@cursor_position = 1
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/ifilter.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'ifilter/version'
|
2
|
+
require 'ifilter/interface'
|
3
|
+
require 'ifilter/input'
|
4
|
+
|
5
|
+
module Ifilter
|
6
|
+
def self.filtering(repositories)
|
7
|
+
name = caller.last.match(/.+\/(.+?)(:|\.)/)[1].capitalize
|
8
|
+
|
9
|
+
isatty = STDOUT.isatty
|
10
|
+
|
11
|
+
unless isatty
|
12
|
+
stdout_old = STDOUT.dup
|
13
|
+
STDOUT.reopen('/dev/tty')
|
14
|
+
end
|
15
|
+
|
16
|
+
ifilter = Interface.new(name, repositories)
|
17
|
+
result = ifilter.grep
|
18
|
+
|
19
|
+
unless isatty
|
20
|
+
STDOUT.flush
|
21
|
+
STDOUT.reopen(stdout_old)
|
22
|
+
end
|
23
|
+
|
24
|
+
result
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ifilter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kaihar4
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: curses
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Interactive Filter.
|
70
|
+
email:
|
71
|
+
- kaihar4@gmail.com
|
72
|
+
executables:
|
73
|
+
- ifilter
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/ifilter
|
83
|
+
- ifilter.gemspec
|
84
|
+
- lib/ifilter.rb
|
85
|
+
- lib/ifilter/input.rb
|
86
|
+
- lib/ifilter/interface.rb
|
87
|
+
- lib/ifilter/version.rb
|
88
|
+
homepage: https://github.com/kaihar4/ifilter
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Interactive Filter.
|
112
|
+
test_files: []
|