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/lib/Search_Engine.rb CHANGED
@@ -1,165 +1,165 @@
1
1
  # Copyright (c) 2005 Martin Ankerl
2
2
  class Search_Engine
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
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
- 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)
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
- 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
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
- attr_accessor :print_prompt, :gets_mode
24
+ attr_accessor :print_prompt, :gets_mode
25
25
 
26
26
  def initialize
27
- super
27
+ super
28
28
  @history = 1
29
- @begin = nil
30
- @print_prompt = true
31
- @end = nil
32
- @continued_from = nil
33
- @gets_mode = false
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
- 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
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
- @line_no += 1
64
- @history = @line_no + 1
65
- @line[@line_no] = str
63
+ @line_no += 1
64
+ @history = @line_no + 1
65
+ @line[@line_no] = str
66
66
 
67
- str
67
+ str
68
68
  end
69
69
 
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
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
- return "" if @gets_mode
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
- return "" if @gets_mode
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
- IRB.initialize(nil)
106
- IRB.parse_opts
107
- IRB.load_modules
108
- else
109
- IRB.setup(nil)
110
- end
111
- IRB.restart(im)
112
- end
113
-
114
- def IRB.restart(im)
115
- irb = Irb.new(nil, im)
116
-
117
- @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
118
- @CONF[:MAIN_CONTEXT] = irb.context
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
- def gets
125
- inp = IRB.conf[:MAIN_CONTEXT].io
126
- inp.gets_mode = true
127
- retval = IRB.conf[:MAIN_CONTEXT].io.gets
128
- inp.gets_mode = false
129
- retval
130
- end
131
- end
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
- end
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
- include Singleton
145
- include Responder
146
-
147
- attr_reader :input
148
-
149
- def FXIrb.init(p, tgt, sel, opts)
150
- unless @__instance__
151
- Thread.critical = true
152
- begin
153
- @__instance__ ||= new(p, tgt, sel, opts)
154
- ensure
155
- Thread.critical = false
156
- end
157
- end
158
- return @__instance__
159
- end
160
-
161
- def initialize(p, tgt, sel, opts)
162
- @parent = p
163
- FXMAPFUNC(SEL_KEYRELEASE, 0, "onKeyRelease")
164
- FXMAPFUNC(SEL_KEYPRESS, 0, "onKeyPress")
165
- FXMAPFUNC(SEL_LEFTBUTTONPRESS,0,"onLeftBtnPress")
166
- FXMAPFUNC(SEL_MIDDLEBUTTONPRESS,0,"onMiddleBtnPress")
167
- FXMAPFUNC(SEL_LEFTBUTTONRELEASE,0,"onLeftBtnRelease")
168
-
169
- super
170
- setFont(FXFont.new(FXApp.instance, "lucida console", 9))
171
- @anchor = 0
172
- end
173
-
174
- def create
175
- super
176
- restart
177
- end
178
-
179
- def restart
180
- setFocus
181
- setText("")
182
- # IRB initialization
183
- @inputAdded = 0
184
- @input = IO.pipe
185
- $DEFAULT_OUTPUT = self
186
-
187
- @im = FXIRBInputMethod.new
188
- if @irb
189
- @irb.kill
190
- @irb = Thread.new {
191
- IRB.restart(@im)
192
- }
193
- else
194
- @irb = Thread.new {
195
- IRB.start_in_fxirb(@im)
196
- }
197
- end
198
- end
199
-
200
-
201
- def onKeyRelease(sender, sel, event)
202
- case event.code
203
- when Fox::KEY_Return, Fox::KEY_KP_Enter
204
- newLineEntered
205
- end
206
- return 1
207
- end
208
-
209
- def onKeyPress(sender,sel,event)
210
- case event.code
211
- when Fox::KEY_Return, Fox::KEY_KP_Enter
212
- setCursorPos(getLength)
213
- super
214
- when Fox::KEY_Up,Fox::KEY_KP_Up
215
- str = extractText(@anchor, getCursorPos-@anchor)
216
- if str =~ /\n/
217
- @multiline = true
218
- super
219
- setCursorPos(@anchor+1) if getCursorPos < @anchor
220
- else
221
- history(:prev) unless @multiline
222
- end
223
- when Fox::KEY_Down,Fox::KEY_KP_Down
224
- str = extractText(getCursorPos, getLength - getCursorPos)
225
- if str =~ /\n/
226
- @multiline = true
227
- super
228
- else
229
- history(:next) unless @multiline
230
- end
231
- when Fox::KEY_Left,Fox::KEY_KP_Left
232
- if getCursorPos > @anchor
233
- super
234
- end
235
- when Fox::KEY_Delete,Fox::KEY_KP_Delete,Fox::KEY_BackSpace
236
- if getCursorPos > @anchor
237
- super
238
- end
239
- when Fox::KEY_Home, Fox::KEY_KP_Home
240
- setCursorPos(@anchor)
241
- when Fox::KEY_End, Fox::KEY_KP_End
242
- setCursorPos(getLength)
243
- when Fox::KEY_Page_Up, Fox::KEY_KP_Page_Up
244
- history(:prev)
245
- when Fox::KEY_Page_Down, Fox::KEY_KP_Page_Down
246
- history(:next)
247
- when Fox::KEY_bracketright
248
- #auto-dedent if the } or ] is on a line by itself
249
- if (emptyline? or (getline == "en")) and indented?
250
- dedent
251
- end
252
- super
253
- when Fox::KEY_u
254
- if (event.state & CONTROLMASK) != 0
255
- str = extractText(getCursorPos, getLength - getCursorPos)
256
- rmline
257
- appendText(str)
258
- setCursorPos(@anchor)
259
- end
260
- super
261
- when Fox::KEY_k
262
- if (event.state & CONTROLMASK) != 0
263
- str = extractText(@anchor, getCursorPos-@anchor)
264
- rmline
265
- appendText(str)
266
- setCursorPos(getLength)
267
- end
268
- super
269
- when Fox::KEY_d
270
- if (event.state & CONTROLMASK) != 0
271
- restart
272
- =begin
273
- #Ctrl - D
274
- rmline
275
- appendText(exit)
276
- sendCommand("exit")
277
- newLineEntered
278
- =end
279
- else
280
- # test for 'end' so we can dedent
281
- if (getline == "en") and indented?
282
- str = getline
283
- @anchor -= 2
284
- rmline
285
- appendText(str)
286
- setCursorPos(getLength)
287
- end
288
- end
289
- super
290
- else
291
- super
292
- end
293
- end
294
-
295
- def dedent
296
- str = getline
297
- @anchor -= 2
298
- rmline
299
- appendText(str)
300
- setCursorPos(getLength)
301
- end
302
-
303
- def history(dir)
304
- str = (dir == :prev) ? @im.prevCmd.chomp : @im.nextCmd.chomp
305
- if str != ""
306
- removeText(@anchor, getLength-@anchor)
307
- write(str)
308
- end
309
- end
310
-
311
- def getline
312
- extractText(@anchor, getLength-@anchor)
313
- end
314
-
315
- def rmline
316
- str = getline
317
- removeText(@anchor, getLength-@anchor)
318
- str
319
- end
320
-
321
- def emptyline?
322
- getline == ""
323
- end
324
-
325
- def indented?
326
- extractText(@anchor-2, 2) == " "
327
- end
328
-
329
- def onLeftBtnPress(sender,sel,event)
330
- @store_anchor = @anchor
331
- setFocus
332
- super
333
- end
334
-
335
- def onLeftBtnRelease(sender,sel,event)
336
- super
337
- @anchor = @store_anchor
338
- setCursorPos(@anchor)
339
- setCursorPos(getLength)
340
- end
341
-
342
- def onMiddleBtnPress(sender,sel,event)
343
- pos=getPosAt(event.win_x,event.win_y)
344
- if pos >= @anchor
345
- super
346
- end
347
- end
348
-
349
- def newLineEntered
350
- processCommandLine(extractText(@anchor, getLength-@anchor))
351
- end
352
-
353
- def processCommandLine(cmd)
354
- @multiline = false
355
- lines = cmd.split(/\n/)
356
- lines.each {|i|
357
- @input[1].puts i
358
- @inputAdded += 1
359
- }
360
- @im.print_prompt = false
361
- while (@inputAdded > 0) do
362
- @irb.run
363
- end
364
- @im.merge_last(lines.length)
365
- @im.print_prompt = true
366
- end
367
-
368
- def sendCommand(cmd)
369
- setCursorPos(getLength)
370
- makePositionVisible(getLength) unless isPosVisible(getLength)
371
- cmd += "\n"
372
- appendText(cmd)
373
- processCommandLine(cmd)
374
- end
375
-
376
- def write(obj)
377
- str = obj.to_s
378
- appendText(str)
379
- setCursorPos(getLength)
380
- makePositionVisible(getLength) unless isPosVisible(getLength)
381
- return str.length
382
- end
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
- application = FXApp.new("FXIrb", "ruby")
397
- application.threadsEnabled = true
398
- Thread.abort_on_exception = true
399
- application.init(ARGV)
400
- window = FXMainWindow.new(application, "FXIrb", nil, nil, DECOR_ALL, 0, 0, 580, 500)
401
- fxirb = FXIrb.init(window, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y|TEXT_WORDWRAP|TEXT_SHOWACTIVE)
402
- application.create
403
- window.show(PLACEMENT_SCREEN)
404
- application.run
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
-