@@ -26,28 +26,28 @@ def print_file files_so_far, filename
26
26
files_so_far ,
27
27
@num_files )
28
28
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 } "
42
29
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
+
43
42
# Clean the line with whitespaces so that leftover output from the
44
43
# previous line doesn't show up.
45
44
$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 "
48
47
else
49
- $stdout . puts ( line )
48
+ term = " \n "
50
49
end
50
+ $stdout. print ( progress_bar , filename , term )
51
51
$stdout. flush
52
52
end
53
53
0 commit comments