Sha256: 29829ab71286b01bf6652a026dec75ed97b6550751d1dec905d7021fb2753147

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

# coding: utf-8

module Gitrob
  class ProgressBar
    TITLE_MAX_LENGTH = 25

    def initialize(message, options)
      @options = {
        :format         => " #{Paint['[*]', :bright, :blue]} %c/%C %B %j% %e",
        :progress_mark  => Paint['▓', :bright, :blue],
        :remainder_mark => '░',
      }.merge(options)
      Gitrob::status(message)
      @mutex = Mutex.new
      @progress_bar = ::ProgressBar::Base.new(@options)
    end

    def finish!
      @mutex.synchronize { @progress_bar.finish }
    end

    def log(message)
      @mutex.synchronize do
        @progress_bar.log(" #{Paint['[>]', :bright, :blue]} #{message}")
      end
    end

    def log_error(message)
      @mutex.synchronize do
        @progress_bar.log(" #{Paint['[!]', :bright, :red]} #{message}")
      end
    end

    def method_missing(method, *args, &block)
      if @progress_bar.respond_to?(method)
        @mutex.synchronize { @progress_bar.send(method, *args, &block) }
      else
        super
      end
    end

  private

    def make_title(t)
      t = t.to_s
      if t.size > TITLE_MAX_LENGTH
        t = "#{t[0, (TITLE_MAX_LENGTH-3)]}..."
      end
      " #{Paint['[>]', :bright, :blue]} #{Paint[t.rjust(TITLE_MAX_LENGTH), :bright, :blue]}"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gitrob-0.0.6 lib/gitrob/progressbar.rb
gitrob-0.0.5 lib/gitrob/progressbar.rb
gitrob-0.0.4 lib/gitrob/progressbar.rb
gitrob-0.0.3 lib/gitrob/progressbar.rb
gitrob-0.0.2 lib/gitrob/progressbar.rb
gitrob-0.0.1 lib/gitrob/progressbar.rb