2013-02-22 80 views
1

我想在Ruby中編寫一個小控制檯腳本來爲我運行我的測試。我以Peter Cooper的this Rake task爲基礎。如何在我的Ruby控制檯實用程序中清除終端?

它可以工作,但如果在每次運行之前清除控制檯將會很好。

有人能告訴我如何使它做到這一點?

這是我到目前爲止有:

require 'find' 
files = {} 

session_count = 0 

puts "Watching #{File.expand_path(File.dirname(__FILE__))}." 

loop do 
    changed = false 
    Find.find(File.dirname(__FILE__)) do |file| 
    next unless file =~ /\.rb$/ 
    ctime = File.ctime(file).to_i 

    if ctime != files[file] 
     files[file] = ctime 
     changed = true 
    end 
    end 

    if changed 

    command = 'ruby -Itest test/**/*_test.rb' 

    puts '---------------------------------------------------------------------------------------------------------' 
    puts "[#{session_count}] #### Running:\n  #{command}" 
    puts '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -' 

    puts `#{command}` 

    puts '---------------------------------------------------------------------------------------------------------' 
    puts "[#{session_count}] #### Done" 
    puts '---------------------------------------------------------------------------------------------------------' 

    session_count += 1 

    end 

    sleep 1 
end 

我在Mac OS 10.7.5和使用巖組4.3.11。

回答

3

你可以這樣做:

if changed 
    system('clear') 
...