fxri 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/fxri +260 -258
- data/fxri.gemspec +16 -16
- data/fxri.kpf +66 -0
- data/lib/Empty_Text_Field_Handler.rb +57 -57
- data/lib/FoxDisplayer.rb +146 -146
- data/lib/FoxTextFormatter.rb +270 -260
- data/lib/Globals.rb +3 -2
- data/lib/Icon_Loader.rb +30 -30
- data/lib/Packet_Item.rb +167 -167
- data/lib/Packet_List.rb +187 -187
- data/lib/Recursive_Open_Struct.rb +205 -205
- data/lib/RiManager.rb +133 -133
- data/lib/Search_Engine.rb +159 -159
- data/lib/fxirb.rb +321 -332
- metadata +51 -42
data/lib/Search_Engine.rb
CHANGED
@@ -1,165 +1,165 @@
|
|
1
1
|
# Copyright (c) 2005 Martin Ankerl
|
2
2
|
class Search_Engine
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
3
|
+
def initialize(gui, data)
|
4
|
+
@gui = gui
|
5
|
+
@data = data
|
6
|
+
@search_thread = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
# Executed whenever a search criteria changes to update the packet list.
|
10
|
+
def on_search
|
11
|
+
# restart current search
|
12
|
+
@end_time = Time.now + $cfg.search_delay
|
13
|
+
@restart_search = true
|
14
|
+
@gui.search_label.enabled = false
|
15
|
+
return if @search_thread && @search_thread.status
|
16
|
+
|
17
|
+
@search_thread = Thread.new(@search_thread) do
|
18
|
+
begin
|
19
|
+
@gui.search_label.enabled = false
|
20
|
+
# wait untill deadline
|
21
|
+
while (t = (@end_time - Time.now)) > 0
|
22
|
+
sleep(t)
|
23
|
+
end
|
24
|
+
|
25
|
+
@data.gui_mutex.synchronize do
|
26
|
+
# the thread has to use the gui mutex inside
|
27
|
+
@restart_search = false
|
28
|
+
|
29
|
+
match_data = get_match_data
|
30
|
+
|
31
|
+
# remove all items
|
32
|
+
@gui.packet_list.dirty_clear
|
33
|
+
|
34
|
+
# add all items that match the search criteria
|
35
|
+
status_text_deadline = Time.now + $cfg.status_line_update_interval
|
36
|
+
@data.items.each do |item|
|
37
|
+
#item.parent = @gui.packet_list if match?(item, match_data)
|
38
|
+
if match?(item, match_data)
|
39
|
+
item.show
|
40
|
+
now = Time.now
|
41
|
+
if now > status_text_deadline
|
42
|
+
update_search_status_text
|
43
|
+
status_text_deadline = now + $cfg.status_line_update_interval
|
44
|
+
end
|
45
|
+
end
|
46
|
+
break if @restart_search
|
47
|
+
end
|
48
|
+
update_search_status_text
|
49
|
+
|
50
|
+
if (@gui.packet_list.numItems > 0)
|
51
|
+
@gui.packet_list.setCurrentItem(0)
|
52
|
+
@gui.packet_list.selectItem(0)
|
53
|
+
@gui.main.show_info(@gui.packet_list.getItem(0).packet_item.data)
|
54
|
+
end
|
55
|
+
@gui.search_label.enabled = true
|
56
|
+
|
57
|
+
end # synchronize
|
58
|
+
end while @restart_search# || match_data != @gui.search_field.text.downcase.split
|
59
|
+
end #thread.new
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_match_data
|
63
|
+
str_to_match_data(@gui.search_field.text)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Converts a string into a match_data representation.
|
67
|
+
def str_to_match_data(str, index=0)
|
68
|
+
words = [ ]
|
69
|
+
exclude = [ ]
|
70
|
+
is_exclude = false
|
71
|
+
|
72
|
+
while str[index]
|
73
|
+
case str[index]
|
74
|
+
when ?", ?'
|
75
|
+
word, index = get_word(str, index+1, str[index])
|
76
|
+
unless word.empty?
|
77
|
+
if is_exclude
|
78
|
+
exclude.push word
|
79
|
+
is_exclude = false
|
80
|
+
else
|
81
|
+
words.push word
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
when 32 # space
|
86
|
+
is_exclude = false
|
87
87
|
|
88
88
|
=begin
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
when ?>
|
90
|
+
min, index = get_word(str, index+1)
|
91
|
+
min = @gui.logic.size_to_nr(min)
|
92
|
+
|
93
|
+
when ?<
|
94
|
+
max, index = get_word(str, index+1)
|
95
|
+
max = @gui.logic.size_to_nr(max)
|
96
96
|
=end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
97
|
+
when ?-
|
98
|
+
is_exclude = true
|
99
|
+
|
100
|
+
else
|
101
|
+
word, index = get_word(str, index)
|
102
|
+
if is_exclude
|
103
|
+
exclude.push word
|
104
|
+
is_exclude = false
|
105
|
+
else
|
106
|
+
words.push word
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
index += 1
|
111
|
+
end
|
112
|
+
|
113
|
+
# check if word has upcase letters
|
114
|
+
words.collect! do |w|
|
115
|
+
[w, /[A-Z]/.match(w)!=nil]
|
116
|
+
end
|
117
|
+
exclude.collect! do |w|
|
118
|
+
[w, /[A-Z]/.match(w)!=nil]
|
119
|
+
end
|
120
|
+
[words, exclude]
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_word(str, index, delim=32) # 32==space
|
124
|
+
word = ""
|
125
|
+
c = str[index]
|
126
|
+
while (c && c != delim)
|
127
|
+
word += c.chr
|
128
|
+
index += 1
|
129
|
+
c = str[index]
|
130
|
+
end
|
131
|
+
[word, index]
|
132
|
+
end
|
133
|
+
|
134
|
+
# Update the text for the number of displayed packs.
|
135
|
+
def update_search_status_text
|
136
|
+
@gui.search_label.text = sprintf($cfg.text.search, @gui.packet_list.numItems, @data.items.size)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Find out if item is matched by current search criteria.
|
140
|
+
def match?(item, match_data)
|
141
|
+
words, exclude, min, max = match_data
|
142
|
+
|
143
|
+
# check text that has to be there
|
144
|
+
searchable, sortable_downcase, sortable_normal = item.sortable(0)
|
145
|
+
words.each do |match_str, is_sensitive|
|
146
|
+
if is_sensitive
|
147
|
+
return false unless sortable_normal.include?(match_str)
|
148
|
+
else
|
149
|
+
return false unless sortable_downcase.include?(match_str)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# check text not allowed to be there
|
154
|
+
exclude.each do |match_str, is_sensitive|
|
155
|
+
if is_sensitive
|
156
|
+
return false if sortable_normal.include?(match_str)
|
157
|
+
else
|
158
|
+
return false if sortable_downcase.include?(match_str)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# each check ok
|
163
|
+
true
|
164
|
+
end
|
165
165
|
end
|
data/lib/fxirb.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
# Credits:
|
8
8
|
# - Initial linux version: Gilles Filippini
|
9
9
|
# - Initial windows port : Marco Frailis
|
10
|
-
# - Currently maintained and developed by
|
10
|
+
# - Currently maintained and developed by
|
11
11
|
# Martin DeMello <martindemello@gmail.com>
|
12
12
|
|
13
13
|
require "fox12"
|
@@ -21,64 +21,64 @@ STDOUT.sync = true
|
|
21
21
|
|
22
22
|
class FXIRBInputMethod < IRB::StdioInputMethod
|
23
23
|
|
24
|
-
|
24
|
+
attr_accessor :print_prompt, :gets_mode
|
25
25
|
|
26
26
|
def initialize
|
27
|
-
super
|
27
|
+
super
|
28
28
|
@history = 1
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
@begin = nil
|
30
|
+
@print_prompt = true
|
31
|
+
@end = nil
|
32
|
+
@continued_from = nil
|
33
|
+
@gets_mode = false
|
34
34
|
end
|
35
35
|
|
36
|
-
def gets
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
36
|
+
def gets
|
37
|
+
if @gets_mode
|
38
|
+
return FXIrb.instance.get_line
|
39
|
+
end
|
40
|
+
|
41
|
+
if (a = @prompt.match(/(\d+)[>*]/))
|
42
|
+
level = a[1].to_i
|
43
|
+
else
|
44
|
+
level = 0
|
45
|
+
end
|
46
|
+
|
47
|
+
if level > 0
|
48
|
+
@continued_from ||= @line_no
|
49
|
+
elsif @continued_from
|
50
|
+
merge_last(@line_no-@continued_from+1)
|
51
|
+
@continued_from = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
if @print_prompt
|
55
|
+
print @prompt
|
56
|
+
|
57
|
+
#indentation
|
58
|
+
print " "*level
|
59
|
+
end
|
60
60
|
|
61
61
|
str = FXIrb.instance.get_line
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
@line_no += 1
|
64
|
+
@history = @line_no + 1
|
65
|
+
@line[@line_no] = str
|
66
66
|
|
67
|
-
|
67
|
+
str
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
# merge a block spanning several lines into one \n-separated line
|
71
|
+
def merge_last(i)
|
72
|
+
return unless i > 1
|
73
|
+
range = -i..-1
|
74
|
+
@line[range] = @line[range].map {|l| l.chomp}.join("\n")
|
75
|
+
@line_no -= (i-1)
|
76
|
+
@history -= (i-1)
|
77
|
+
end
|
78
78
|
|
79
79
|
def prevCmd
|
80
|
-
|
81
|
-
|
80
|
+
return "" if @gets_mode
|
81
|
+
|
82
82
|
if @line_no > 0
|
83
83
|
@history -= 1 unless @history <= 1
|
84
84
|
return line(@history)
|
@@ -87,7 +87,7 @@ class FXIRBInputMethod < IRB::StdioInputMethod
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def nextCmd
|
90
|
-
|
90
|
+
return "" if @gets_mode
|
91
91
|
|
92
92
|
if (@line_no > 0) && (@history < @line_no)
|
93
93
|
@history += 1
|
@@ -102,37 +102,34 @@ module IRB
|
|
102
102
|
|
103
103
|
def IRB.start_in_fxirb(im)
|
104
104
|
if RUBY_VERSION < "1.7.3"
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
trap("SIGINT") do
|
120
|
-
irb.signal_handle
|
121
|
-
end
|
105
|
+
IRB.initialize(nil)
|
106
|
+
IRB.parse_opts
|
107
|
+
IRB.load_modules
|
108
|
+
else
|
109
|
+
IRB.setup(nil)
|
110
|
+
end
|
111
|
+
|
112
|
+
irb = Irb.new(nil, im)
|
113
|
+
|
114
|
+
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
|
115
|
+
@CONF[:MAIN_CONTEXT] = irb.context
|
116
|
+
trap("SIGINT") do
|
117
|
+
irb.signal_handle
|
118
|
+
end
|
122
119
|
|
123
120
|
class << irb.context.workspace.main
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
121
|
+
def gets
|
122
|
+
inp = IRB.conf[:MAIN_CONTEXT].io
|
123
|
+
inp.gets_mode = true
|
124
|
+
retval = IRB.conf[:MAIN_CONTEXT].io.gets
|
125
|
+
inp.gets_mode = false
|
126
|
+
retval
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
133
130
|
catch(:IRB_EXIT) do
|
134
131
|
irb.eval_input
|
135
|
-
|
132
|
+
end
|
136
133
|
print "\n"
|
137
134
|
|
138
135
|
end
|
@@ -141,266 +138,258 @@ end
|
|
141
138
|
|
142
139
|
|
143
140
|
class FXIrb < FXText
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
def get_line
|
385
|
-
@anchor = getLength
|
386
|
-
if @inputAdded == 0
|
387
|
-
Thread.stop
|
388
|
-
end
|
389
|
-
@inputAdded -= 1
|
390
|
-
return @input[0].gets
|
391
|
-
end
|
141
|
+
include Singleton
|
142
|
+
include Responder
|
143
|
+
|
144
|
+
attr_reader :input
|
145
|
+
|
146
|
+
def FXIrb.init(p, tgt, sel, opts)
|
147
|
+
unless @__instance__
|
148
|
+
Thread.critical = true
|
149
|
+
begin
|
150
|
+
@__instance__ ||= new(p, tgt, sel, opts)
|
151
|
+
ensure
|
152
|
+
Thread.critical = false
|
153
|
+
end
|
154
|
+
end
|
155
|
+
return @__instance__
|
156
|
+
end
|
157
|
+
|
158
|
+
def initialize(p, tgt, sel, opts)
|
159
|
+
FXMAPFUNC(SEL_KEYRELEASE, 0, "onKeyRelease")
|
160
|
+
FXMAPFUNC(SEL_KEYPRESS, 0, "onKeyPress")
|
161
|
+
FXMAPFUNC(SEL_LEFTBUTTONPRESS,0,"onLeftBtnPress")
|
162
|
+
FXMAPFUNC(SEL_MIDDLEBUTTONPRESS,0,"onMiddleBtnPress")
|
163
|
+
FXMAPFUNC(SEL_LEFTBUTTONRELEASE,0,"onLeftBtnRelease")
|
164
|
+
|
165
|
+
super
|
166
|
+
setFont(FXFont.new(FXApp.instance, "lucida console", 9))
|
167
|
+
@anchor = 0
|
168
|
+
end
|
169
|
+
|
170
|
+
def create
|
171
|
+
super
|
172
|
+
setFocus
|
173
|
+
# IRB initialization
|
174
|
+
@inputAdded = 0
|
175
|
+
@input = IO.pipe
|
176
|
+
$DEFAULT_OUTPUT = self
|
177
|
+
|
178
|
+
@im = FXIRBInputMethod.new
|
179
|
+
@irb = Thread.new {
|
180
|
+
IRB.start_in_fxirb(@im)
|
181
|
+
self.crash
|
182
|
+
}
|
183
|
+
|
184
|
+
|
185
|
+
@multiline = false
|
186
|
+
|
187
|
+
@exit_proc = lambda {exit}
|
188
|
+
end
|
189
|
+
|
190
|
+
def on_exit(&block)
|
191
|
+
@exit_proc = block
|
192
|
+
end
|
193
|
+
|
194
|
+
def crash
|
195
|
+
instance_eval(&@exit_proc)
|
196
|
+
end
|
197
|
+
|
198
|
+
def onKeyRelease(sender, sel, event)
|
199
|
+
case event.code
|
200
|
+
when Fox::KEY_Return, Fox::KEY_KP_Enter
|
201
|
+
newLineEntered
|
202
|
+
end
|
203
|
+
return 1
|
204
|
+
end
|
205
|
+
|
206
|
+
def onKeyPress(sender,sel,event)
|
207
|
+
case event.code
|
208
|
+
when Fox::KEY_Return, Fox::KEY_KP_Enter
|
209
|
+
setCursorPos(getLength)
|
210
|
+
super
|
211
|
+
when Fox::KEY_Up,Fox::KEY_KP_Up
|
212
|
+
str = extractText(@anchor, getCursorPos-@anchor)
|
213
|
+
if str =~ /\n/
|
214
|
+
@multiline = true
|
215
|
+
super
|
216
|
+
setCursorPos(@anchor+1) if getCursorPos < @anchor
|
217
|
+
else
|
218
|
+
history(:prev) unless @multiline
|
219
|
+
end
|
220
|
+
when Fox::KEY_Down,Fox::KEY_KP_Down
|
221
|
+
str = extractText(getCursorPos, getLength - getCursorPos)
|
222
|
+
if str =~ /\n/
|
223
|
+
@multiline = true
|
224
|
+
super
|
225
|
+
else
|
226
|
+
history(:next) unless @multiline
|
227
|
+
end
|
228
|
+
when Fox::KEY_Left,Fox::KEY_KP_Left
|
229
|
+
if getCursorPos > @anchor
|
230
|
+
super
|
231
|
+
end
|
232
|
+
when Fox::KEY_Delete,Fox::KEY_KP_Delete,Fox::KEY_BackSpace
|
233
|
+
if getCursorPos > @anchor
|
234
|
+
super
|
235
|
+
end
|
236
|
+
when Fox::KEY_Home, Fox::KEY_KP_Home
|
237
|
+
setCursorPos(@anchor)
|
238
|
+
when Fox::KEY_End, Fox::KEY_KP_End
|
239
|
+
setCursorPos(getLength)
|
240
|
+
when Fox::KEY_Page_Up, Fox::KEY_KP_Page_Up
|
241
|
+
history(:prev)
|
242
|
+
when Fox::KEY_Page_Down, Fox::KEY_KP_Page_Down
|
243
|
+
history(:next)
|
244
|
+
when Fox::KEY_bracketright
|
245
|
+
#auto-dedent if the } or ] is on a line by itself
|
246
|
+
if (emptyline? or (getline == "en")) and indented?
|
247
|
+
dedent
|
248
|
+
end
|
249
|
+
super
|
250
|
+
when Fox::KEY_u
|
251
|
+
if (event.state & CONTROLMASK) != 0
|
252
|
+
str = extractText(getCursorPos, getLength - getCursorPos)
|
253
|
+
rmline
|
254
|
+
appendText(str)
|
255
|
+
setCursorPos(@anchor)
|
256
|
+
end
|
257
|
+
super
|
258
|
+
when Fox::KEY_k
|
259
|
+
if (event.state & CONTROLMASK) != 0
|
260
|
+
str = extractText(@anchor, getCursorPos-@anchor)
|
261
|
+
rmline
|
262
|
+
appendText(str)
|
263
|
+
setCursorPos(getLength)
|
264
|
+
end
|
265
|
+
super
|
266
|
+
when Fox::KEY_d
|
267
|
+
if (event.state & CONTROLMASK) != 0
|
268
|
+
#Ctrl - D
|
269
|
+
rmline
|
270
|
+
appendText("exit")
|
271
|
+
newLineEntered
|
272
|
+
else
|
273
|
+
# test for 'end' so we can dedent
|
274
|
+
if (getline == "en") and indented?
|
275
|
+
dedent
|
276
|
+
end
|
277
|
+
end
|
278
|
+
super
|
279
|
+
else
|
280
|
+
super
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def dedent
|
285
|
+
str = getline
|
286
|
+
@anchor -= 2
|
287
|
+
rmline
|
288
|
+
appendText(str)
|
289
|
+
setCursorPos(getLength)
|
290
|
+
end
|
291
|
+
|
292
|
+
def history(dir)
|
293
|
+
str = (dir == :prev) ? @im.prevCmd.chomp : @im.nextCmd.chomp
|
294
|
+
if str != ""
|
295
|
+
removeText(@anchor, getLength-@anchor)
|
296
|
+
write(str)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def getline
|
301
|
+
extractText(@anchor, getLength-@anchor)
|
302
|
+
end
|
303
|
+
|
304
|
+
def rmline
|
305
|
+
str = getline
|
306
|
+
removeText(@anchor, getLength-@anchor)
|
307
|
+
str
|
308
|
+
end
|
309
|
+
|
310
|
+
def emptyline?
|
311
|
+
getline == ""
|
312
|
+
end
|
313
|
+
|
314
|
+
def indented?
|
315
|
+
extractText(@anchor-2, 2) == " "
|
316
|
+
end
|
317
|
+
|
318
|
+
def onLeftBtnPress(sender,sel,event)
|
319
|
+
@store_anchor = @anchor
|
320
|
+
setFocus
|
321
|
+
super
|
322
|
+
end
|
323
|
+
|
324
|
+
def onLeftBtnRelease(sender,sel,event)
|
325
|
+
super
|
326
|
+
@anchor = @store_anchor
|
327
|
+
setCursorPos(@anchor)
|
328
|
+
setCursorPos(getLength)
|
329
|
+
end
|
330
|
+
|
331
|
+
def onMiddleBtnPress(sender,sel,event)
|
332
|
+
pos=getPosAt(event.win_x,event.win_y)
|
333
|
+
if pos >= @anchor
|
334
|
+
super
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
def newLineEntered
|
339
|
+
processCommandLine(extractText(@anchor, getLength-@anchor))
|
340
|
+
end
|
341
|
+
|
342
|
+
def processCommandLine(cmd)
|
343
|
+
@multiline = false
|
344
|
+
lines = cmd.split(/\n/)
|
345
|
+
lines.each {|i|
|
346
|
+
@input[1].puts i
|
347
|
+
@inputAdded += 1
|
348
|
+
}
|
349
|
+
@im.print_prompt = false
|
350
|
+
while (@inputAdded > 0) do
|
351
|
+
@irb.run
|
352
|
+
end
|
353
|
+
@im.merge_last(lines.length)
|
354
|
+
@im.print_prompt = true
|
355
|
+
end
|
356
|
+
|
357
|
+
def sendCommand(cmd)
|
358
|
+
setCursorPos(getLength)
|
359
|
+
makePositionVisible(getLength) unless isPosVisible(getLength)
|
360
|
+
cmd += "\n"
|
361
|
+
appendText(cmd)
|
362
|
+
processCommandLine(cmd)
|
363
|
+
end
|
364
|
+
|
365
|
+
def write(obj)
|
366
|
+
str = obj.to_s
|
367
|
+
appendText(str)
|
368
|
+
setCursorPos(getLength)
|
369
|
+
makePositionVisible(getLength) unless isPosVisible(getLength)
|
370
|
+
return str.length
|
371
|
+
end
|
372
|
+
|
373
|
+
def get_line
|
374
|
+
@anchor = getLength
|
375
|
+
if @inputAdded == 0
|
376
|
+
Thread.stop
|
377
|
+
end
|
378
|
+
@inputAdded -= 1
|
379
|
+
return @input[0].gets
|
380
|
+
end
|
392
381
|
end
|
393
382
|
|
394
383
|
# Stand alone run
|
395
384
|
if __FILE__ == $0
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
385
|
+
application = FXApp.new("FXIrb", "ruby")
|
386
|
+
application.threadsEnabled = true
|
387
|
+
Thread.abort_on_exception = true
|
388
|
+
application.init(ARGV)
|
389
|
+
window = FXMainWindow.new(application, "FXIrb", nil, nil, DECOR_ALL, 0, 0, 580, 500)
|
390
|
+
fxirb = FXIrb.init(window, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y|TEXT_WORDWRAP|TEXT_SHOWACTIVE)
|
391
|
+
application.create
|
392
|
+
window.show(PLACEMENT_SCREEN)
|
393
|
+
fxirb.on_exit {exit}
|
394
|
+
application.run
|
405
395
|
end
|
406
|
-
|