Skip to content

Commit 384ea4c

Browse files
committed
Log full lines unless output is a tty
1 parent 773bb29 commit 384ea4c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

lib/rdoc/stats/normal.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,28 @@ def print_file files_so_far, filename
2626
files_so_far,
2727
@num_files)
2828

29-
# Print a progress bar, but make sure it fits on a single line. Filename
30-
# will be truncated if necessary.
31-
size = IO.respond_to?(:console_size) ? IO.console_size : IO.console.winsize
32-
terminal_width = size[1].to_i.nonzero? || 80
33-
max_filename_size = terminal_width - progress_bar.size
34-
35-
if filename.size > max_filename_size then
36-
# Turn "some_long_filename.rb" to "...ong_filename.rb"
37-
filename = filename[(filename.size - max_filename_size) .. -1]
38-
filename[0..2] = "..."
39-
end
40-
41-
line = "#{progress_bar}#{filename}"
4229
if $stdout.tty?
30+
# Print a progress bar, but make sure it fits on a single line. Filename
31+
# will be truncated if necessary.
32+
size = IO.respond_to?(:console_size) ? IO.console_size : IO.console.winsize
33+
terminal_width = size[1].to_i.nonzero? || 80
34+
max_filename_size = terminal_width - progress_bar.size
35+
36+
if filename.size > max_filename_size then
37+
# Turn "some_long_filename.rb" to "...ong_filename.rb"
38+
filename = filename[(filename.size - max_filename_size) .. -1]
39+
filename[0..2] = "..."
40+
end
41+
4342
# Clean the line with whitespaces so that leftover output from the
4443
# previous line doesn't show up.
4544
$stdout.print("\r\e[K") if @last_width && @last_width > 0
46-
@last_width = line.size
47-
$stdout.print("#{line}\r")
45+
@last_width = progress_bar.size + filename.size
46+
term = "\r"
4847
else
49-
$stdout.puts(line)
48+
term = "\n"
5049
end
50+
$stdout.print(progress_bar, filename, term)
5151
$stdout.flush
5252
end
5353

0 commit comments

Comments
 (0)