require "fileutils" require "term/ansicolor" class Out class << self include ::Term::ANSIColor def out(msg, color=nil) m = msg if color puts send(color.to_sym, m) else puts m end #write_tmp(m) msgs << m end def write_tmp(ctn) if save? unless ctn.match(%r{^\s*$}) tmp_ctn = tmp tmp_ctn << "At #{Time.now}" tmp_ctn << ctn File.write(tmp_path, tmp_ctn.join("\n")) end else if test(?s, tmp_path) and test(?s, tmp_path) > 10_000 FileUtils.rm_f(tmp_path) end end end def save? @save end def save_on File.write(tmp_path, "save_on at #{Time.now}") @save = true end def save_off File.write(tmp_path, "save_on at #{Time.now}") @save = false end def save @save ||= false end def tmp_path FileUtils.touch "/tmp/ro_out" @tmp_path ||= "/tmp/ro_out" end def tmp if test(?f, tmp_path) File.readlines(tmp_path).delete_if do |l| l.blank? end else FileUtils.touch tmp_path [] end end def reset @msgs = [] end def msgs @msgs.flatten! if @msgs.respond_to?(:flatten!) @msgs = [] if @msgs and @msgs.length > 999 @msgs ||= [] end #class Msg # def initialize(msg) # @msg = msg # end # # def to_s # @msg # end #end end end