Class: Output

Inherits:
ArcadiaExt show all
Defined in:
ext/ae-output/ae-output.rb

Constant Summary collapse

MARKSUF =
'mark-'
PROMPT_SIMBOL =

PROMPT_SIMBOL=‘$’

'>'

Instance Attribute Summary collapse

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods inherited from ArcadiaExt

#add_to_conf_property, #array_conf, #conf, #conf_array, #conf_default, #del_from_conf_property, #destroy_frame, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_raised?, #frame_title, #frame_visible?, #hide_frame, #hinner_dialog, #hinner_splitted_dialog, #hinner_splitted_dialog_titled, #initialize, #maximize, #maximized?, #resize, #restore_default_conf

Constructor Details

This class inherits a constructor from ArcadiaExt

Instance Attribute Details

#main_frameObject (readonly)

Returns the value of attribute main_frame.



172
173
174
# File 'ext/ae-output/ae-output.rb', line 172

def main_frame
  @main_frame
end

#promptObject (readonly)

Returns the value of attribute prompt.



173
174
175
# File 'ext/ae-output/ae-output.rb', line 173

def prompt
  @prompt
end

Instance Method Details

#file_binding(_file, _line, _ibegin, _iend) ⇒ Object



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
385
386
387
388
389
390
# File 'ext/ae-output/ae-output.rb', line 348

def file_binding(_file, _line, _ibegin, _iend)
  if defined?(@file_binding)
    while @file_binding
      sleep(1)
    end
  end
  @file_binding=true
  begin
    if _file == '<<current buffer>>'
      _file = "*CURR"
    end
    _line = '0' if _line.nil? || _line.strip.length == 0
    tag_name = next_tag_name
    @main_frame.text.tag_configure(tag_name,
      'foreground' => Arcadia.conf('hightlight.link.foreground'),
      'borderwidth'=>0,
      'relief'=>'flat',
      'underline'=>true
    )
    @main_frame.text.tag_add(tag_name,_ibegin,_iend)
    #@main_frame.text.tag_bind(tag_name,"Double-ButtonPress-1",
    @main_frame.text.tag_bind(tag_name,"ButtonPress-1",
      proc{OpenBufferTransientEvent.new(self,'file'=>_file, 'row'=>_line).go!}
#        proc{OpenBufferEvent.new(self,'file'=>_file, 'row'=>_line).go!}
    )
    @main_frame.text.tag_bind(tag_name,"Enter",
      proc{@main_frame.text.configure('cursor'=> 'hand2')}
    )
    @main_frame.text.tag_bind(tag_name,"Leave",
      proc{@main_frame.text.configure('cursor'=> @cursor)}
    )

    if @main_frame.auto_open_file?
      OpenBufferEvent.new(self,'file'=>_file, 'row'=>_line, 'debug'=>'yes').go!
#        OpenBufferEvent.new(self,'file'=>_file, 'row'=>_line).go!
      self.frame.show
      @main_frame.text.set_focus
      @main_frame.text.see("end")
    end
  ensure
    @file_binding = false
  end
end

#format_time(_time) ⇒ Object



194
195
196
# File 'ext/ae-output/ae-output.rb', line 194

def format_time(_time)
  _time.strftime("at %a %d-%b-%Y %H:%M:%S")
end

#next_tag_nameObject



343
344
345
346
# File 'ext/ae-output/ae-output.rb', line 343

def next_tag_name
  @tag_seq = @tag_seq + 1 
  "tag_#{@tag_seq}"
end

#on_after_build(_event) ⇒ Object



190
191
192
# File 'ext/ae-output/ae-output.rb', line 190

def on_after_build(_event)
  self.frame.show
end

#on_before_build(_event) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
# File 'ext/ae-output/ae-output.rb', line 177

def on_before_build(_event)
  #ArcadiaContractListener.new(self, MsgContract, :do_msg_event)
  @tag_seq = 0
  @writing=false
  @prompt_active = false
  @prompt = PROMPT_SIMBOL 
  Arcadia.attach_listener(self, MsgEvent)
  Arcadia.attach_listener(self, InputKeyboardQueryEvent)
  #_frame = @arcadia.layout.register_panel('_rome_',@name, 'Output')
  @main_frame = OutputView.new(self)
  @run_threads = Array.new
end

#on_input_keyboard_query(_event) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'ext/ae-output/ae-output.rb', line 275

def on_input_keyboard_query(_event)
  if _event.pid
    @prompt = "~#{_event.pid} #{PROMPT_SIMBOL} "
  end
  @prompt_active = true
  sync_insert("end", @prompt, 'prompt')
  @main_frame.text.focus
  @main_frame.text.see("end")
  prompt_index = @main_frame.text.index("insert")
  @main_frame.input_buffer = nil
  while @main_frame.input_buffer.nil? && !_event.is_breaked?
    sleep(0.1)
  end
  if !_event.is_breaked?
    _event.add_result(self, 'input'=>@main_frame.input_buffer)
    @main_frame.text.tag_add("prompt","#{prompt_index} linestart","#{prompt_index} lineend")
  else
    if @main_frame.text.get("end -1 lines linestart", "end -1 lines lineend").strip == @prompt.strip
      @main_frame.text.delete("end -1 lines linestart", "end -1 lines lineend")
    end
  end
  @main_frame.input_buffer = nil
  @prompt_active = false
end

#on_msg(_event) ⇒ Object



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
# File 'ext/ae-output/ae-output.rb', line 198

def on_msg(_event)
  self.frame.show if !self.frame.raised?
  if _event.mark
    _mark_index = _event.mark.sub(MARKSUF,'');
    _index_begin = "#{_mark_index} + 1 lines + 1 chars"

    #_index_begin = "#{@main_frame.text.index(_event.mark)} + 1 lines + 1 chars"
    #       _b = Tk::BWidget::Button.new(@main_frame.text,
    #         'helptext'=>Time.now.strftime("-> %d-%b-%Y %H:%M:%S"),
    #         'background'=>Arcadia.style('edit')['background'],
    #         'borderwidth'=>0,
    #         'image'=> TkPhotoImage.new('data' => ITEM_LOG_GIF),
    #         'relief'=>'flat')
    #       TkTextWindow.new(@main_frame.text, _index_begin, 'window'=> _b)
    #       TkTextImage.new(@main_frame.text, _index_begin, 'padx'=>0, 'pady'=>0, 'image'=> TkPhotoImage.new('data' => ITEM_LOG_GIF))
  else
    @main_frame.text.insert("end","\n")
    _index_begin = @main_frame.text.index('end')
#      TkTextImage.new(@main_frame.text, _index_begin, 'padx'=>0, 'pady'=>0, 'image'=> Arcadia.image_res(ITEM_START_LOG_GIF))
#      sync_insert("end"," +--- #{format_time(_event.time)} ---+\n", 'info_msg')
    sync_insert("end","===== #{format_time(_event.time)} ======\n", 'info_msg')
  end
  if _event.append
    _index_begin = "#{@main_frame.text.index(_index_begin)} - 2 lines lineend"
    _txt = _event.msg
  elsif _event.msg[-1] == "\n"
    _txt = _event.msg
  else
    _txt = "#{_event.msg}\n"
  end
#    if _event.level == 'error'
#      TkTextImage.new(@main_frame.text, _index_begin, 'padx'=>0, 'pady'=>0, 'image'=> TkPhotoImage.new('data' => ERROR_9X9_GIF))
#    end
  #@main_frame.text.insert(_index_begin,_txt, "#{_event.level}_msg")
  sync_insert(_index_begin,_txt, "#{_event.level}_msg")
  _index_end = @main_frame.text.index('end')
  if ['debug','error'].include?(_event.level)
    parse_begin_row = _index_begin.split('.')[0].to_i-2
    parse_end_row = _index_end.split('.')[0].to_i
    parse_debug(parse_begin_row, parse_end_row)
  end
  @main_frame.text.see(_index_end)
  @main_frame.text.mark_unset(_event.mark)
  _event.mark="#{MARKSUF}#{_index_end}"
  @main_frame.text.mark_set(_event.mark, "#{_index_end} - 1 lines -1 chars")
  #     if _event.instance_of?(MsgRunEvent)
  #       _b = TkButton.new(@main_frame.text,
  #         'command'=>proc{_event.abort_action.call;_b.destroy},
  #         'image'=> TkPhotoImage.new('data' => CLOSE_GIF),
  #         'relief'=>'groove')
  #       TkTextWindow.new(@main_frame.text, 'end', 'window'=> _b)
  #     end

end

#out(_txt = nil, _tag = nil) ⇒ Object



392
393
394
395
396
397
398
399
400
401
# File 'ext/ae-output/ae-output.rb', line 392

def out(_txt=nil, _tag=nil)
  if @main_frame && _txt
    sync_insert('end', _txt, _tag)
#      if _tag
#        @main_frame.text.insert('end',_txt, _tag)
#      else
#        @main_frame.text.insert('end',_txt)
#      end
  end
end

#outln(_txt = nil, _tag = nil) ⇒ Object



403
404
405
# File 'ext/ae-output/ae-output.rb', line 403

def outln(_txt=nil, _tag=nil)
  self.out(_txt+"\n",_tag)
end

#parse_debug(_from_row = 0, _to_row = -1)) ⇒ Object



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
# File 'ext/ae-output/ae-output.rb', line 301

def parse_debug(_from_row=0, _to_row=-1)
  return if _from_row == _to_row
  _row = _from_row
  @cursor = @main_frame.text.cget('cursor')
  file_tag=Hash.new
  if String.method_defined?(:lines)
    lines = @main_frame.text.value.lines.to_a[_from_row.._to_row]
  else
    lines = @main_frame.text.value.to_a[_from_row.._to_row]
  end
  
#  p "parso "
  
  if lines
    lines.each{|l|
      _row = _row+1
      #if _row >= _from_row
      _end = 0
      #m = /([\.\/]*[\/A-Za-z_\-\.]*[\.\/\w\d]*\.rb):(\d*)/.match(l)
      re = Regexp.new('([\w\:]*[\.\/]*[\/A-Za-z0-9_\-\.\~]*[\.\/\w\d]*[(<<current buffer>>)]*):(\d*)')
      m = re.match(l)
      #m = /([\.\/]*[\/A-Za-z_\-\.]*[\.\/\w\d]*):(\d*)/.match(l)
      while m
        _txt = m.post_match
        if m[1] && m[2]
          _file = m[1]
          if File.exist?(_file) || _file=="<<current buffer>>"  
             _line = m[2]
            _ibegin = _row.to_s+'.'+(m.begin(1)+_end).to_s
            _iend = _row.to_s+'.'+(m.end(2)+_end).to_s
            file_binding(_file, _line, _ibegin, _iend)
          end
          _end = m.end(2) + _end
        end
        m = re.match(_txt)
      end
      #m = re.match(_txt)
      #end
    }
  end
end

#sync_insert(_index, _txt, _tag = nil) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'ext/ae-output/ae-output.rb', line 253

def sync_insert(_index, _txt, _tag=nil)
  begin
    while @writing
      sleep(0.1)
    end
    @writing = true
    if @prompt_active
      start =  @main_frame.text.get("#{_index} -1 lines linestart", _index).strip
      if start == @prompt.strip
        _index = "#{_index} -1 lines linestart"
      end
    end
    if _tag
      @main_frame.text.insert(_index, _txt, _tag)
    else
      @main_frame.text.insert(_index, _txt)
    end
  ensure
    @writing = false
  end
end