Skip to content

Commit

Permalink
Fixed error when terminal width is zero - fixes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Dec 27, 2024
1 parent 9ca1de4 commit 8863891
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/informers/pipelines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ def call(
stream = $stderr
tty = stream.tty?
width = tty ? stream.winsize[1] : 80
width = 80 if width == 0

if msg[:status] == "progress" && tty
stream.print "\r#{Utils::Hub.display_progress(msg[:file], width, msg[:size], msg[:total_size])}"
Expand Down
4 changes: 2 additions & 2 deletions lib/informers/utils/hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def self.path_join(*parts)
end

def self.display_progress(filename, width, size, expected_size)
bar_width = width - (filename.length + 3)
progress = size / expected_size.to_f
bar_width = [width - (filename.length + 3), 1].max
progress = expected_size ? size / expected_size.to_f : 0
done = (progress * bar_width).round
not_done = bar_width - done
"#{filename} |#{"█" * done}#{" " * not_done}|"
Expand Down

0 comments on commit 8863891

Please sign in to comment.