1## 2# Stats printer that prints just the files being documented with a progress 3# bar 4 5class RDoc::Stats::Normal < RDoc::Stats::Quiet 6 7 def begin_adding # :nodoc: 8 puts "Parsing sources..." if $stdout.tty? 9 end 10 11 ## 12 # Prints a file with a progress bar 13 14 def print_file files_so_far, filename 15 return unless $stdout.tty? 16 17 progress_bar = sprintf("%3d%% [%2d/%2d] ", 18 100 * files_so_far / @num_files, 19 files_so_far, 20 @num_files) 21 22 # Print a progress bar, but make sure it fits on a single line. Filename 23 # will be truncated if necessary. 24 terminal_width = (ENV['COLUMNS'] || 80).to_i 25 max_filename_size = terminal_width - progress_bar.size 26 27 if filename.size > max_filename_size then 28 # Turn "some_long_filename.rb" to "...ong_filename.rb" 29 filename = filename[(filename.size - max_filename_size) .. -1] 30 filename[0..2] = "..." 31 end 32 33 # Pad the line with whitespaces so that leftover output from the 34 # previous line doesn't show up. 35 line = "#{progress_bar}#{filename}" 36 padding = terminal_width - line.size 37 line << (" " * padding) if padding > 0 38 39 $stdout.print("#{line}\r") 40 $stdout.flush 41 end 42 43 def done_adding # :nodoc: 44 puts if $stdout.tty? 45 end 46 47end 48 49