Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the silent option. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions lib/rake-progressbar.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- encoding : utf-8 -*-

class RakeProgressbar
attr_accessor :maximal, :actual, :cols, :finish, :started, :percent, :last_percent, :last_time_dif
attr_accessor :maximal, :actual, :cols, :finish, :started, :percent, :last_percent, :last_time_dif, :silent

def initialize(maximal)
def initialize(maximal, silence = false)
if maximal.nil? || maximal < 1
return nil
else
Expand All @@ -14,6 +14,7 @@ def initialize(maximal)
self.cols = detect_terminal_size[0] - 3 if detect_terminal_size
self.cols = 80 if self.cols.nil? || self.cols < 80
self.finish = false
self.silent = silence
if maximal == 0
puts "nothing to do"
else
Expand All @@ -35,6 +36,10 @@ def inc
end

def display
if self.silent
return nil
end

time_dif = ((Time.now - self.started)).to_i
if self.percent == 0
remaining = 0
Expand Down Expand Up @@ -68,13 +73,17 @@ def finished(show_actual = false)
if self.maximal != 0
display
end
STDOUT.print "\n"
if show_actual
STDOUT.print "Finished #{self.actual} in #{Time.now - self.started}s\n"
else
STDOUT.print "Finished in #{Time.now - self.started}s\n"

unless self.silent
STDOUT.print "\n"
if show_actual
STDOUT.print "Finished #{self.actual} in #{Time.now - self.started}s\n"
else
STDOUT.print "Finished in #{Time.now - self.started}s\n"
end
STDOUT.flush
end
STDOUT.flush

self.finish = true
end
end
Expand Down
2 changes: 1 addition & 1 deletion rake-progressbar.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |s|
s.name = "rake-progressbar"
s.version = "0.0.5"
s.version = "0.0.6"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ondrej Bartas"]
Expand Down