2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2014-09-04 21:41:25 -04:00
|
|
|
begin
|
|
|
|
require 'io/console/size'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2014-07-05 21:00:34 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Stats printer that prints just the files being documented with a progress
|
|
|
|
# bar
|
|
|
|
|
|
|
|
class RDoc::Stats::Normal < RDoc::Stats::Quiet
|
|
|
|
|
|
|
|
def begin_adding # :nodoc:
|
2014-05-20 02:39:08 -04:00
|
|
|
puts "Parsing sources..."
|
2014-07-05 21:00:29 -04:00
|
|
|
@last_width = 0
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Prints a file with a progress bar
|
|
|
|
|
|
|
|
def print_file files_so_far, filename
|
|
|
|
progress_bar = sprintf("%3d%% [%2d/%2d] ",
|
|
|
|
100 * files_so_far / @num_files,
|
|
|
|
files_so_far,
|
|
|
|
@num_files)
|
|
|
|
|
2011-05-12 19:41:35 -04:00
|
|
|
# Print a progress bar, but make sure it fits on a single line. Filename
|
|
|
|
# will be truncated if necessary.
|
2014-09-04 21:41:25 -04:00
|
|
|
terminal_width = if defined?(IO) && IO.respond_to?(:console_size)
|
|
|
|
IO.console_size[1].to_i.nonzero? || 80
|
|
|
|
else
|
|
|
|
80
|
|
|
|
end
|
2011-05-12 19:41:35 -04:00
|
|
|
max_filename_size = terminal_width - progress_bar.size
|
|
|
|
|
|
|
|
if filename.size > max_filename_size then
|
|
|
|
# Turn "some_long_filename.rb" to "...ong_filename.rb"
|
|
|
|
filename = filename[(filename.size - max_filename_size) .. -1]
|
|
|
|
filename[0..2] = "..."
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
2011-05-12 19:41:35 -04:00
|
|
|
line = "#{progress_bar}#{filename}"
|
2014-05-20 02:39:08 -04:00
|
|
|
if $stdout.tty?
|
2014-07-05 21:00:29 -04:00
|
|
|
# Clean the line with whitespaces so that leftover output from the
|
2014-05-20 02:39:08 -04:00
|
|
|
# previous line doesn't show up.
|
2014-07-05 21:00:29 -04:00
|
|
|
$stdout.print("\r" << (" " * @last_width) << ("\b" * @last_width) << "\r") if @last_width && @last_width > 0
|
2014-07-05 21:03:36 -04:00
|
|
|
@last_width = line.size
|
2014-05-20 02:39:08 -04:00
|
|
|
$stdout.print("#{line}\r")
|
|
|
|
else
|
|
|
|
$stdout.puts(line)
|
|
|
|
end
|
2010-12-19 22:22:49 -05:00
|
|
|
$stdout.flush
|
|
|
|
end
|
|
|
|
|
|
|
|
def done_adding # :nodoc:
|
2014-05-20 02:39:08 -04:00
|
|
|
puts
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|