Sha256: 1455928af91dc924fe130668acb3d2ea2dc9c90191bff5b0d03e490fcf705cff

Contents?: true

Size: 1.55 KB

Versions: 42

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true
begin
  require 'io/console/size'
rescue LoadError
  # for JRuby
  require 'io/console'
end

##
# Stats printer that prints just the files being documented with a progress
# bar

class RDoc::Stats::Normal < RDoc::Stats::Quiet

  def begin_adding # :nodoc:
    puts "Parsing sources..."
    @last_width = 0
  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)

    if $stdout.tty?
      # Print a progress bar, but make sure it fits on a single line. Filename
      # will be truncated if necessary.
      size = IO.respond_to?(:console_size) ? IO.console_size : IO.console.winsize
      terminal_width = size[1].to_i.nonzero? || 80
      max_filename_size = (terminal_width - progress_bar.size) - 1

      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] = "..."
      end

      # Clean the line with whitespaces so that leftover output from the
      # previous line doesn't show up.
      $stdout.print("\r\e[K") if @last_width && @last_width > 0
      @last_width = progress_bar.size + filename.size
      term = "\r"
    else
      term = "\n"
    end
    $stdout.print(progress_bar, filename, term)
    $stdout.flush
  end

  def done_adding # :nodoc:
    puts
  end

end

Version data entries

42 entries across 40 versions & 9 rubygems

Version Path
rdoc-6.12.0 lib/rdoc/stats/normal.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rdoc-6.11.0/lib/rdoc/stats/normal.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/rdoc-6.7.0/lib/rdoc/stats/normal.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rdoc-6.8.1/lib/rdoc/stats/normal.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rdoc-6.10.0/lib/rdoc/stats/normal.rb
rdoc-6.11.0 lib/rdoc/stats/normal.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rdoc-6.7.0/lib/rdoc/stats/normal.rb
rdoc-6.10.0 lib/rdoc/stats/normal.rb
rdoc-6.9.1 lib/rdoc/stats/normal.rb
rdoc-6.9.0 lib/rdoc/stats/normal.rb
rdoc-6.8.1 lib/rdoc/stats/normal.rb
rdoc-6.8.0 lib/rdoc/stats/normal.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rdoc-6.7.0/lib/rdoc/stats/normal.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rdoc-6.7.0/lib/rdoc/stats/normal.rb
rdoc-6.6.3.1 lib/rdoc/stats/normal.rb
rdoc-6.5.1.1 lib/rdoc/stats/normal.rb
rdoc-6.4.1.1 lib/rdoc/stats/normal.rb
rdoc-6.3.4.1 lib/rdoc/stats/normal.rb
rdoc-6.6.2 lib/rdoc/stats/normal.rb
rdoc-6.6.1 lib/rdoc/stats/normal.rb