require "phi" ; include Phi
require "DosCmd"

form = Form.new :form, "起動"
memo = Memo.new form
memo.align = AL_CLIENT
cmd  = DosCommand.new form
##cmd  = DosCommand.new
cmd.command_line = 'cmd /c dir /w /s \\ '
cmd.max_time_after_beginning=10

memo.on_dbl_click = proc{
  if cmd.active?
    cmd.stop
  else
    cmd.execute
  end
}

#-- on_new_line 相当のハンドラ

cnt = 0
memo.on_change=proc{p cnt+=1 }

#-- on_terminated 相当のハンドラ。

cmd.on_terminate = proc{|sender|
  p :on_terminate
  p sender
  p sender.command_line
  p sender.since_beginning
  p sender.since_last_output
}

#lines = StringList.new
#cmd.output_lines = lines
#cmd.execute2
#puts lines.to_a
#memo.lines.text = lines.text

form.show
cmd.output_lines = memo.lines
cmd.execute2
puts :xxx
#puts memo.lines.to_a
#puts :yyy

##cmd.output_lines = memo.lines
##cmd.execute
##puts :xxx
##puts memo.lines.to_a
##puts :yyy

form.on_close_query = proc{
  p :on_close_query
  cmd.stop ; 
}
form.on_close       = proc{
  p :on_close
  cmd.stop ; 
}

#form.show
mainloop 
