Class: Shell
- Inherits:
-
ArcadiaExt
- Object
- ArcadiaExt
- Shell
- Defined in:
- ext/ae-shell/ae-shell.rb
Overview
require “base/a-utils”
Constant Summary collapse
- @@next_number =
0
Instance Attribute Summary
Attributes inherited from ArcadiaExt
Instance Method Summary collapse
- #is_windows? ⇒ Boolean
- #on_before_build(_event) ⇒ Object
- #on_build(_event) ⇒ Object
- #on_run_ruby_file(_event) ⇒ Object
- #on_system_exec(_event) ⇒ Object
- #on_system_exec_bo(_event) ⇒ Object
- #run(_filename = nil) ⇒ Object
- #run_current ⇒ Object
- #run_last ⇒ Object
- #stop ⇒ Object
Methods inherited from ArcadiaExt
#conf, #conf_array, #exec, #float_frame, #frame, #frame_def_visible?, #frame_visible?, #initialize, #maximize, #maximized?, #resize
Constructor Details
This class inherits a constructor from ArcadiaExt
Instance Method Details
#is_windows? ⇒ Boolean
133 134 135 |
# File 'ext/ae-shell/ae-shell.rb', line 133 def is_windows? RUBY_PLATFORM =~ /mingw|mswin/ end |
#on_before_build(_event) ⇒ Object
11 12 13 14 |
# File 'ext/ae-shell/ae-shell.rb', line 11 def on_before_build(_event) Arcadia.attach_listener(self, SystemExecEvent) Arcadia.attach_listener(self, RunRubyFileEvent) end |
#on_build(_event) ⇒ Object
16 17 18 |
# File 'ext/ae-shell/ae-shell.rb', line 16 def on_build(_event) @run_threads = Array.new end |
#on_run_ruby_file(_event) ⇒ Object
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'ext/ae-shell/ae-shell.rb', line 48 def on_run_ruby_file(_event) _filename = _event.file _filename = @arcadia['pers']['run.file.last'] if _filename == "*LAST" if _filename && File.exists?(_filename) begin Arcadia.console(self,'msg'=>"Running #{_filename}...", 'level'=>'debug') # info? start_time = Time.now @arcadia['pers']['run.file.last']=_filename if _event.persistent executable = @arcadia['conf']['shell.ruby'] executable = @arcadia['conf']['shell.rubyw'] if is_windows? _cmd_ = "#{executable} -C'#{File.dirname(_filename)}' '#{_filename}'" if is_windows? # use win32-process gem to startup a child process [not sure if linux needs something like this, too] require 'win32/process' require 'ruby-wmi' output_file_name = "out_#{@@next_number += 1}_#{Process.pid}.txt" output = File.open(output_file_name, 'wb') child = Process.create :command_line => _cmd_, :startup_info => {:stdout => output, :stderr => output} timer=nil procy = proc { still_alive = WMI::Win32_Process.find(:first, :conditions => {:ProcessId => child.process_id}) if(!still_alive) output.close timer.stop File.open(output_file_name, 'r') do |f| _readed = f.read _readed.strip! _readed += "\n" + "Done with #{_filename} in #{Time.now - start_time}s" Arcadia.console(self,'msg'=>_readed, 'level'=>'debug') _event.add_result(self, 'output'=>_readed) end File.delete output_file_name end } timer=TkAfter.new(1000,-1,procy) # -1 = repeating every 1000ms... timer.start else _cmd_ = "|#{_cmd_} 2>&1" Thread.new { begin open(_cmd_, "r"){|f| _readed = f.read Arcadia.console(self,'msg'=>_readed, 'level'=>'debug') _event.add_result(self, 'output'=>_readed) } rescue Exception => e Arcadia.console(self,'msg'=>e.to_s, 'level'=>'debug') end } end rescue Exception => e Arcadia.console(self,'msg'=>e.to_s, 'level'=>'debug') end end end |
#on_system_exec(_event) ⇒ Object
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 |
# File 'ext/ae-shell/ae-shell.rb', line 20 def on_system_exec(_event) begin # _cmd_ = "|ruby #{File.dirname(__FILE__)}/sh.rb #{_event.command} 2>&1" # p _cmd_ # Thread.new do # open(_cmd_,"r"){|f| # Arcadia.new_debug_msg(self, f.read) # } # end _cmd_ = "#{_event.command}" if is_windows? io = IO.popen(_cmd_) Arcadia.console(self,'msg'=>io.read, 'level'=>'debug') else Process.fork{ open(_cmd_,"r"){|f| Arcadia.console(self,'msg'=>f.read, 'level'=>'debug') #Arcadia.new_debug_msg(self, f.read) } } end rescue Exception => e Arcadia.console(self,'msg'=>e, 'level'=>'debug') #Arcadia.new_debug_msg(self, e) end end |
#on_system_exec_bo(_event) ⇒ Object
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 |
# File 'ext/ae-shell/ae-shell.rb', line 106 def on_system_exec_bo(_event) command = "#{_event.command} 2>&1" (RUBY_PLATFORM.include?('mswin32'))?_cmd="cmd":_cmd='sh' if is_windows? Thread.new{ Arcadia.console(self,'msg'=>'begin', 'level'=>'debug') #Arcadia.new_debug_msg(self, 'inizio') @io = IO.popen(_cmd,'r+') @io.puts(command) result = '' while line = @io.gets result << line end #Arcadia.new_debug_msg(self, result) Arcadia.console(self,'msg'=>result, 'level'=>'debug') } else Process.fork{ open(_cmd_,"r"){|f| Arcadia.console(self,'msg'=>f.read, 'level'=>'debug') #Arcadia.new_debug_msg(self, f.read) } } end end |
#run(_filename = nil) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'ext/ae-shell/ae-shell.rb', line 155 def run(_filename=nil) if _filename begin @arcadia['pers']['run.file.last']=_filename @run_threads << Thread.new do _cmd_ = "|"+$arcadia['conf']['shell.ruby']+" "+_filename+" 2>&1" # Arcadia.new_debug_msg(self, _cmd_) @cmd = open(_cmd_,"r"){|f| Arcadia.console(self, 'msg'=>f.read ,'level'=>'debug') #Arcadia.new_debug_msg(self, f.read) } end rescue Exception => e Arcadia.console(self, 'msg'=>e ,'level'=>'debug') #Arcadia.new_debug_msg(self, e) end end end |
#run_current ⇒ Object
141 142 143 144 |
# File 'ext/ae-shell/ae-shell.rb', line 141 def run_current current_editor = $arcadia['editor'].raised run(current_editor.file) if current_editor end |
#run_last ⇒ Object
137 138 139 |
# File 'ext/ae-shell/ae-shell.rb', line 137 def run_last run($arcadia['pers']['run.file.last']) end |
#stop ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'ext/ae-shell/ae-shell.rb', line 146 def stop @run_threads.each{|t| if t.alive? t.kill end } debug_quit if @adw end |