lib/td/command/common.rb in td-0.11.9 vs lib/td/command/common.rb in td-0.11.10

- old
+ new

@@ -1,9 +1,11 @@ require 'td/version' module TreasureData +require "td/config" + autoload :API, 'td/client/api' autoload :Client, 'td/client' autoload :Database, 'td/client' autoload :Table, 'td/client' autoload :Schema, 'td/client' @@ -247,19 +249,19 @@ def ask_password(max=3, &block) 3.times do begin system "stty -echo" # TODO termios - print "Password (typing will be hidden): " + $stdout.print "Password (typing will be hidden): " password = STDIN.gets || "" password = password[0..-2] # strip \n rescue Interrupt $stderr.print "\ncanceled." exit 1 ensure system "stty echo" # TODO termios - print "\n" + $stdout.print "\n" end if password.empty? $stderr.puts "canceled." exit 0 @@ -326,11 +328,11 @@ end class DownloadProgressIndicator def initialize(msg) @base_msg = msg - print @base_msg + " " * 10 + $stdout.print @base_msg + " " * 10 end end class TimeBasedDownloadProgressIndicator < DownloadProgressIndicator def initialize(msg, start_time, periodicity = 2) @@ -341,21 +343,21 @@ end def update if (time = Time.now.to_i) - @last_time >= @periodicity msg = "\r#{@base_msg}: #{Command.humanize_elapsed_time(@start_time, time)} elapsed" - print "\r" + " " * (msg.length + 10) - print msg + $stdout.print "\r" + " " * (msg.length + 10) + $stdout.print msg @last_time = time true else false end end def finish - puts "\r#{@base_msg}...done" + " " * 20 + $stdout.puts "\r#{@base_msg}...done" + " " * 20 end end class SizeBasedDownloadProgressIndicator < DownloadProgressIndicator def initialize(msg, size, perc_step = 1, min_periodicity = nil) @@ -376,29 +378,29 @@ end def update(curr_size) if @size.nil? || @size == 0 msg = "\r#{@base_msg}: #{Command.humanize_bytesize(curr_size)}" - print msg + $stdout.print msg true else ratio = (curr_size.to_f * 100 / @size).round(1) if ratio >= (@last_perc_step + @perc_step) && (!@min_periodicity || (time = Time.now.to_i) - @last_time >= @min_periodicity) msg = "\r#{@base_msg}: #{Command.humanize_bytesize(curr_size)} / #{ratio}%" - print "\r" + " " * (msg.length + 10) - print msg + $stdout.print "\r" + " " * (msg.length + 10) + $stdout.print msg @last_perc_step = ratio @last_time = time true else false end end end def finish - print "\r#{@base_msg}...done" + " " * 20 + $stdout.print "\r#{@base_msg}...done" + " " * 20 end end end # module Command end # module TrasureData