ifilter 0.0.5 → 0.0.6
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/interface.rb +19 -9
- data/lib/ifilter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 535ae8eeb3552b29e6e3ee3dfc7558bd7ab59d3a
|
4
|
+
data.tar.gz: 8889c81060a2ff43b9e193978e6941281afed5b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da307d4bfa73ceebb973d6eb2fbff21cee39e629170ca78e2d7482baf27c0a57789fc93569b24f6a08d68e3630c216b041093767603484d0d48ce9c8d44d60f3
|
7
|
+
data.tar.gz: 794a8ead06b801877c05d35567084305ec51a0e534f65317eb276b1776d11c9754c5c8eb39524aee76e461d5abba82ea84e1d2b764a92b5a7648768fa7906814
|
data/lib/ifilter/interface.rb
CHANGED
@@ -54,7 +54,6 @@ module Ifilter
|
|
54
54
|
|
55
55
|
Curses.close_screen
|
56
56
|
@outputs[@cursor_position - 1]
|
57
|
-
|
58
57
|
rescue Interrupt # <C-c>
|
59
58
|
Curses.close_screen
|
60
59
|
end
|
@@ -66,12 +65,14 @@ module Ifilter
|
|
66
65
|
@window.clear
|
67
66
|
reset_cursor_position
|
68
67
|
|
68
|
+
# A flag of the output for paging
|
69
69
|
start_index = (@window.maxy - 1) * (@page_number - 1)
|
70
70
|
# Update @outputs
|
71
71
|
@outputs = filtering_by_input(@target, start_index: start_index)
|
72
72
|
|
73
73
|
# Redraw the output
|
74
74
|
output_line(@prompt + @input.to_s)
|
75
|
+
output_current_page
|
75
76
|
@outputs.each do |output|
|
76
77
|
output_line(output)
|
77
78
|
end
|
@@ -87,6 +88,7 @@ module Ifilter
|
|
87
88
|
def filtering_by_input(array, start_index: 0)
|
88
89
|
array.each_with_object([]).with_index do |(str, outputs), index|
|
89
90
|
next if index < start_index
|
91
|
+
|
90
92
|
regex = @input.to_regex
|
91
93
|
|
92
94
|
if !regex.nil? && regex =~ str
|
@@ -104,12 +106,19 @@ module Ifilter
|
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
109
|
+
def output_current_page
|
110
|
+
word = "[#{@page_number}/#{max_page_number.zero? ? 1 : max_page_number}]"
|
111
|
+
@window.setpos(@cursor_position - 1, @window.maxx)
|
112
|
+
|
113
|
+
@window << (' ' * (@window.maxx - word.size - @prompt.size)) + word
|
114
|
+
end
|
115
|
+
|
107
116
|
def up_cursor_position
|
108
117
|
if @cursor_position == 1
|
109
118
|
scroll_prev_page
|
110
119
|
else
|
111
|
-
@window.setpos(@cursor_position - 1, 0)
|
112
120
|
@cursor_position -= 1
|
121
|
+
@window.setpos(@cursor_position, 0)
|
113
122
|
end
|
114
123
|
end
|
115
124
|
|
@@ -117,14 +126,14 @@ module Ifilter
|
|
117
126
|
if @cursor_position == @window.maxy - 1 || @cursor_position == @outputs.size
|
118
127
|
scroll_next_page
|
119
128
|
else
|
120
|
-
@window.setpos(@cursor_position + 1, 0)
|
121
129
|
@cursor_position += 1
|
130
|
+
@window.setpos(@cursor_position, 0)
|
122
131
|
end
|
123
132
|
end
|
124
133
|
|
125
134
|
def reset_cursor_position
|
126
|
-
@window.setpos(1, 0)
|
127
135
|
@cursor_position = 1
|
136
|
+
@window.setpos(@cursor_position, 0)
|
128
137
|
end
|
129
138
|
|
130
139
|
def scroll_prev_page
|
@@ -132,32 +141,33 @@ module Ifilter
|
|
132
141
|
@page_number = max_page_number
|
133
142
|
update_window
|
134
143
|
|
135
|
-
@window.setpos(last_output_position, 0)
|
136
144
|
@cursor_position = last_output_position
|
145
|
+
@window.setpos(@cursor_position, 0)
|
137
146
|
else
|
138
147
|
@page_number -= 1
|
139
148
|
update_window
|
140
149
|
|
141
|
-
@window.setpos(@window.maxy - 1, 0)
|
142
150
|
@cursor_position = @window.maxy - 1
|
151
|
+
@window.setpos(@cursor_position, 0)
|
143
152
|
end
|
144
153
|
end
|
145
154
|
|
146
155
|
def scroll_next_page
|
147
156
|
if @page_number == max_page_number
|
148
157
|
@page_number = 1
|
158
|
+
update_window
|
149
159
|
else
|
150
160
|
@page_number += 1
|
161
|
+
update_window
|
151
162
|
end
|
152
|
-
update_window
|
153
163
|
end
|
154
164
|
|
155
165
|
def max_page_number
|
156
|
-
(filtering_by_input(@target
|
166
|
+
(filtering_by_input(@target).size.to_f / (@window.maxy - 1).to_f).ceil
|
157
167
|
end
|
158
168
|
|
159
169
|
def last_output_position
|
160
|
-
filtering_by_input(@target
|
170
|
+
filtering_by_input(@target).size % (@window.maxy - 1)
|
161
171
|
end
|
162
172
|
end
|
163
173
|
end
|
data/lib/ifilter/version.rb
CHANGED