lib/progress.rb in progress-1.0.1 vs lib/progress.rb in progress-1.1.0

- old
+ new

@@ -2,11 +2,11 @@ class Progress include Singleton module InstanceMethods # :nodoc: - attr_accessor :title, :current, :total + attr_accessor :title, :current, :total, :note attr_reader :current_step def initialize(title, total) if title.is_a?(Numeric) && total.nil? title, total = nil, title elsif total.nil? @@ -89,10 +89,11 @@ if levels.last set(levels.last.current + Float(num) / den, &block) elsif block block.call end + self.note = nil end def set(value, &block) if levels.last ret = if block @@ -119,10 +120,16 @@ io.puts end end end + def note=(s) + if levels.last + levels.last.note = s + end + end + attr_writer :lines, :highlight # :nodoc: private def levels @@ -206,13 +213,18 @@ eta_string = eta(inner) message = "#{parts.reverse * ' > '}#{eta_string}" message_cl = "#{parts_cl.reverse * ' > '}#{eta_string}" + if note = levels.last.note + message << " - #{note}" + message_cl << " - #{note}" + end + unless lines? previous_length = @previous_length || 0 @previous_length = message_cl.length - message = "#{message}#{' ' * [previous_length - message_cl.length, 0].max}\r" + message << "#{' ' * [previous_length - message_cl.length, 0].max}\r" end lines? ? io.puts(message) : io.print(message) set_title(message_cl) end