forked from ngauthier/hydra
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added progressbar listener and made it the new default
- Loading branch information
Nick Gauthier
committed
Mar 25, 2010
1 parent
02cd1ee
commit 96f4a21
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Hydra #:nodoc: | ||
module Listener #:nodoc: | ||
# Output a progress bar as files are completed | ||
class ProgressBar < Hydra::Listener::Abstract | ||
# Store the total number of files | ||
def testing_begin(files) | ||
@total_files = files.size | ||
@files_completed = 0 | ||
@test_output = "" | ||
@errors = false | ||
render_progress_bar | ||
end | ||
|
||
# Increment completed files count and update bar | ||
def file_end(file, output) | ||
unless output == '.' | ||
@output.write "\r#{' '*60}\r#{output}\n" | ||
@errors = true | ||
end | ||
@files_completed += 1 | ||
render_progress_bar | ||
end | ||
|
||
# Break the line | ||
def testing_end | ||
render_progress_bar | ||
@output.write "\n" | ||
end | ||
|
||
private | ||
|
||
def render_progress_bar | ||
width = 30 | ||
complete = ((@files_completed.to_f / @total_files.to_f) * width).to_i | ||
@output.write "\r" # move to beginning | ||
@output.write 'Progress [' | ||
@output.write @errors ? "\033[1;31m" : "\033[1;32m" | ||
complete.times{@output.write '#'} | ||
@output.write '>' | ||
(width-complete).times{@output.write ' '} | ||
@output.write "\033[0m" | ||
@output.write "] #{@files_completed}/#{@total_files}" | ||
@output.flush | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters