ifilter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/lib/ifilter/client.rb +41 -32
- data/lib/ifilter/version.rb +1 -1
- data/lib/ifilter/window.rb +18 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87bc44ff9b07d7dced65ad01dc151214cf4753ff
|
4
|
+
data.tar.gz: e63a537acc96986989e621d51c94b06da85168af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 598ffac359a6728b9189d1e4c065c1ecdb62f5a4db4d9ed7c33f901b967d2817d07c42c9282f9c8440b9d058776a3c4c579600ae2622b2566885069125445e62
|
7
|
+
data.tar.gz: 682d6f1ccde77971b4166ff4c2687243da80266eb7cb236903d3195fb591f347f93438634a784fb3c8eeba742d56479744e82103ac198e5b9451b112bf955b71
|
data/lib/ifilter/client.rb
CHANGED
@@ -56,7 +56,7 @@ module Ifilter
|
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
|
-
def update_window
|
59
|
+
def update_window(cursor_position: 1)
|
60
60
|
# Initialize a window
|
61
61
|
@window.clear
|
62
62
|
reset_cursor_position
|
@@ -67,18 +67,24 @@ module Ifilter
|
|
67
67
|
@outputs = filtering_by_input(@target, start_index: start_index)
|
68
68
|
|
69
69
|
# Redraw the output
|
70
|
-
|
70
|
+
output_prompt
|
71
71
|
output_current_page
|
72
72
|
@outputs.each do |output|
|
73
|
+
@window.setpos(@cursor_position, 0)
|
73
74
|
output_line(output)
|
75
|
+
@cursor_position += 1
|
74
76
|
end
|
75
|
-
|
77
|
+
|
78
|
+
@cursor_position = cursor_position
|
79
|
+
@window.setpos(@cursor_position, 0)
|
80
|
+
|
81
|
+
highlight_cursor_position
|
76
82
|
end
|
77
83
|
|
78
84
|
def get_keycode(key)
|
79
|
-
Curses.constants.select
|
85
|
+
Curses.constants.select {|name|
|
80
86
|
name =~ /^KEY/ && Curses.const_get(name) == key
|
81
|
-
|
87
|
+
}.first
|
82
88
|
end
|
83
89
|
|
84
90
|
def filtering_by_input(array, start_index: 0)
|
@@ -94,29 +100,34 @@ module Ifilter
|
|
94
100
|
end
|
95
101
|
|
96
102
|
def output_line(word)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
if !@input.size.zero? && @cursor_position > 1 && match_pos = word =~ @input.to_regexp
|
101
|
-
@window << word[0, match_pos]
|
103
|
+
if @cursor_position > @window.maxy - 1
|
104
|
+
return
|
105
|
+
end
|
102
106
|
|
103
|
-
|
104
|
-
|
105
|
-
@window.standend
|
107
|
+
if !@input.size.zero? && match_pos = word =~ @input.to_regexp
|
108
|
+
@window << word[0, match_pos]
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
110
|
+
@window.attrset(Curses.color_pair(3))
|
111
|
+
@window << word[match_pos, @input.size]
|
112
|
+
@window.attrunset(Curses.color_pair(3))
|
111
113
|
|
112
|
-
@
|
114
|
+
@window << word[match_pos + @input.size, word.size - match_pos + @input.size]
|
115
|
+
@window.attrset(Curses.color_pair(1))
|
116
|
+
else
|
117
|
+
@window << word
|
113
118
|
end
|
114
119
|
end
|
115
120
|
|
121
|
+
def output_prompt
|
122
|
+
@window.setpos(0, 0)
|
123
|
+
|
124
|
+
@window << @prompt + @input.to_s
|
125
|
+
end
|
126
|
+
|
116
127
|
def output_current_page
|
117
|
-
|
118
|
-
@window.setpos(@cursor_position - 1, @window.maxx)
|
128
|
+
@window.setpos(0, @window.maxx)
|
119
129
|
|
130
|
+
word = "[#{@page_number}/#{max_page_number.zero? ? 1 : max_page_number}]"
|
120
131
|
@window << (' ' * (@window.maxx - @prompt.size - @input.size - word.size)) + word
|
121
132
|
end
|
122
133
|
|
@@ -124,8 +135,7 @@ module Ifilter
|
|
124
135
|
if @cursor_position == 1
|
125
136
|
scroll_prev_page
|
126
137
|
else
|
127
|
-
@cursor_position
|
128
|
-
@window.setpos(@cursor_position, 0)
|
138
|
+
update_window(cursor_position: @cursor_position - 1)
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
@@ -133,8 +143,7 @@ module Ifilter
|
|
133
143
|
if @cursor_position == @window.maxy - 1 || @cursor_position == @outputs.size
|
134
144
|
scroll_next_page
|
135
145
|
else
|
136
|
-
@cursor_position
|
137
|
-
@window.setpos(@cursor_position, 0)
|
146
|
+
update_window(cursor_position: @cursor_position + 1)
|
138
147
|
end
|
139
148
|
end
|
140
149
|
|
@@ -146,16 +155,10 @@ module Ifilter
|
|
146
155
|
def scroll_prev_page
|
147
156
|
if @page_number == 1
|
148
157
|
@page_number = max_page_number
|
149
|
-
update_window
|
150
|
-
|
151
|
-
@cursor_position = last_output_position
|
152
|
-
@window.setpos(@cursor_position, 0)
|
158
|
+
update_window(cursor_position: last_output_position)
|
153
159
|
else
|
154
160
|
@page_number -= 1
|
155
|
-
update_window
|
156
|
-
|
157
|
-
@cursor_position = @window.maxy - 1
|
158
|
-
@window.setpos(@cursor_position, 0)
|
161
|
+
update_window(cursor_position: @window.maxy - 1)
|
159
162
|
end
|
160
163
|
end
|
161
164
|
|
@@ -169,6 +172,12 @@ module Ifilter
|
|
169
172
|
end
|
170
173
|
end
|
171
174
|
|
175
|
+
def highlight_cursor_position
|
176
|
+
@window.attrset(Curses.color_pair(2))
|
177
|
+
output_line(@outputs[@cursor_position - 1].to_s.slice(0, @window.maxx - 1))
|
178
|
+
@window.attrset(Curses.color_pair(1))
|
179
|
+
end
|
180
|
+
|
172
181
|
def max_page_number
|
173
182
|
(filtering_by_input(@target).size.to_f / (@window.maxy - 1).to_f).ceil
|
174
183
|
end
|
data/lib/ifilter/version.rb
CHANGED
data/lib/ifilter/window.rb
CHANGED
@@ -2,16 +2,33 @@ require 'curses'
|
|
2
2
|
|
3
3
|
module Ifilter
|
4
4
|
class Window < Curses::Window
|
5
|
-
def initialize(
|
5
|
+
def initialize(*args)
|
6
|
+
@previous_colors = []
|
7
|
+
|
6
8
|
Curses.init_screen
|
9
|
+
Curses.start_color
|
7
10
|
Curses.crmode
|
8
11
|
Curses.noecho
|
12
|
+
Curses.curs_set(0) # invisible
|
13
|
+
Curses.init_pair(1, Curses::COLOR_WHITE, Curses::COLOR_BLACK) # default
|
14
|
+
Curses.init_pair(2, Curses::COLOR_BLACK, Curses::COLOR_CYAN) # cursor position
|
15
|
+
Curses.init_pair(3, Curses::COLOR_BLACK, Curses::COLOR_MAGENTA) # match string
|
9
16
|
|
10
17
|
super
|
11
18
|
|
12
19
|
self.keypad(true)
|
13
20
|
end
|
14
21
|
|
22
|
+
def attrset(color_pair)
|
23
|
+
@previous_colors << color_pair
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def attrunset(color_pair)
|
28
|
+
@previous_colors.delete(color_pair)
|
29
|
+
self.attrset(@previous_colors.pop)
|
30
|
+
end
|
31
|
+
|
15
32
|
def close
|
16
33
|
Curses.close_screen
|
17
34
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.4.5
|
139
|
+
rubygems_version: 2.4.5.1
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Interactive Filter
|