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