ifilter 0.2.0 → 0.2.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 +4 -4
- data/lib/ifilter/client.rb +17 -31
- data/lib/ifilter/input.rb +10 -0
- data/lib/ifilter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75be2e647b9ebaf3c9652b9891e1ad4697c0df59
|
4
|
+
data.tar.gz: 5358032cc2dd7af4e0e80488699e75d8780f80e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f910a4502e01599dd89757f3d6812ed0f966beabdcbc972c188bb475c086d025fda143218b6f4817969fa399be7fa99ae3e5a2d186cf416884be444d5418d06d
|
7
|
+
data.tar.gz: c520dc8568894a315cfac375978c4d54de9f01606988e9ab04d1fe5bd014d8b4fca0154bcd9f5ab54aa791e8c9cb6a6ca06c7478e4b793fbb1f683166c7f8b8f
|
data/lib/ifilter/client.rb
CHANGED
@@ -25,9 +25,13 @@ module Ifilter
|
|
25
25
|
|
26
26
|
if key.class == String
|
27
27
|
@input << key
|
28
|
+
@filtered_result = nil
|
29
|
+
@page_number = 1
|
28
30
|
|
29
31
|
elsif key == 127 # <BS>
|
30
32
|
@input.backspace!
|
33
|
+
@filtered_result = nil
|
34
|
+
@page_number = 1
|
31
35
|
|
32
36
|
elsif keycode == :KEY_CTRL_J # <CR>
|
33
37
|
break if @outputs.size >= @cursor_position
|
@@ -40,8 +44,7 @@ module Ifilter
|
|
40
44
|
up_cursor_position unless @outputs.empty?
|
41
45
|
next
|
42
46
|
|
43
|
-
# Ignore other keys
|
44
|
-
else
|
47
|
+
else # Ignore other keys
|
45
48
|
next
|
46
49
|
end
|
47
50
|
|
@@ -64,12 +67,13 @@ module Ifilter
|
|
64
67
|
# A flag of the output for paging
|
65
68
|
start_index = (@window.maxy - 1) * (@page_number - 1)
|
66
69
|
# Update @outputs
|
67
|
-
@outputs =
|
70
|
+
@outputs = filtered_result[start_index, filtered_result.size]
|
68
71
|
|
69
72
|
# Redraw the output
|
70
|
-
|
71
|
-
output_current_page
|
73
|
+
output_header
|
72
74
|
@outputs.each do |output|
|
75
|
+
break if @cursor_position > @window.maxy - 1
|
76
|
+
|
73
77
|
@window.setpos(@cursor_position, 0)
|
74
78
|
output_line(output)
|
75
79
|
@cursor_position += 1
|
@@ -87,23 +91,7 @@ module Ifilter
|
|
87
91
|
}.first
|
88
92
|
end
|
89
93
|
|
90
|
-
def filtering_by_input(array, start_index: 0)
|
91
|
-
array.each_with_object([]).with_index do |(str, outputs), index|
|
92
|
-
next if index < start_index
|
93
|
-
|
94
|
-
regex = @input.to_regexp
|
95
|
-
|
96
|
-
if !regex.nil? && regex =~ str
|
97
|
-
outputs << str
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
94
|
def output_line(word)
|
103
|
-
if @cursor_position > @window.maxy - 1
|
104
|
-
return
|
105
|
-
end
|
106
|
-
|
107
95
|
if !@input.size.zero? && match_pos = word =~ @input.to_regexp
|
108
96
|
@window << word[0, match_pos]
|
109
97
|
|
@@ -111,20 +99,18 @@ module Ifilter
|
|
111
99
|
@window << word[match_pos, @input.size]
|
112
100
|
@window.attrunset(Curses.color_pair(3))
|
113
101
|
|
114
|
-
@window << word[match_pos + @input.size,
|
102
|
+
@window << word[match_pos + @input.size, (@window.maxx - 1) - (match_pos + @input.size)]
|
115
103
|
@window.attrset(Curses.color_pair(1))
|
116
104
|
else
|
117
|
-
@window << word
|
105
|
+
@window << word[0, @window.maxx - 1]
|
118
106
|
end
|
119
107
|
end
|
120
108
|
|
121
|
-
def
|
109
|
+
def output_header
|
122
110
|
@window.setpos(0, 0)
|
123
111
|
|
124
112
|
@window << @prompt + @input.to_s
|
125
|
-
end
|
126
113
|
|
127
|
-
def output_current_page
|
128
114
|
@window.setpos(0, @window.maxx)
|
129
115
|
|
130
116
|
word = "[#{@page_number}/#{max_page_number.zero? ? 1 : max_page_number}]"
|
@@ -155,7 +141,7 @@ module Ifilter
|
|
155
141
|
def scroll_prev_page
|
156
142
|
if @page_number == 1
|
157
143
|
@page_number = max_page_number
|
158
|
-
update_window(cursor_position:
|
144
|
+
update_window(cursor_position: filtered_result.size % (@window.maxy - 1))
|
159
145
|
else
|
160
146
|
@page_number -= 1
|
161
147
|
update_window(cursor_position: @window.maxy - 1)
|
@@ -174,16 +160,16 @@ module Ifilter
|
|
174
160
|
|
175
161
|
def highlight_cursor_position
|
176
162
|
@window.attrset(Curses.color_pair(2))
|
177
|
-
output_line(@outputs[@cursor_position - 1].to_s
|
163
|
+
output_line(@outputs[@cursor_position - 1].to_s)
|
178
164
|
@window.attrset(Curses.color_pair(1))
|
179
165
|
end
|
180
166
|
|
181
167
|
def max_page_number
|
182
|
-
(
|
168
|
+
(filtered_result.size.to_f / (@window.maxy - 1).to_f).ceil
|
183
169
|
end
|
184
170
|
|
185
|
-
def
|
186
|
-
|
171
|
+
def filtered_result
|
172
|
+
@filtered_result ||= @input.filter(@target)
|
187
173
|
end
|
188
174
|
end
|
189
175
|
end
|
data/lib/ifilter/input.rb
CHANGED
data/lib/ifilter/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|