Class: Sus::Output::Bar
- Inherits:
-
Object
- Object
- Sus::Output::Bar
- Defined in:
- lib/sus/output/bar.rb
Overview
Represents a progress bar for displaying test execution progress.
Constant Summary collapse
- BLOCK =
Unicode block characters for drawing the progress bar.
[ " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", ]
- MINIMUM_WIDTH =
The minimum width for the progress bar.
8- MESSAGE_SUFFIX =
The suffix to append to messages.
": "
Class Method Summary collapse
-
.register(output) ⇒ Object
Register progress bar styling with an output handler.
Instance Method Summary collapse
-
#initialize(current = 0, total = 0, message = nil) ⇒ Bar
constructor
Initialize a new progress bar.
-
#print(output) ⇒ Object
Print the progress bar to the output.
-
#update(current, total, message) ⇒ Object
Update the progress bar values.
Constructor Details
#initialize(current = 0, total = 0, message = nil) ⇒ Bar
Initialize a new progress bar.
27 28 29 30 31 32 33 |
# File 'lib/sus/output/bar.rb', line 27 def initialize(current = 0, total = 0, = nil) @maximum_message_width = 0 @current = current @total = total @message = end |
Class Method Details
.register(output) ⇒ Object
Register progress bar styling with an output handler.
47 48 49 |
# File 'lib/sus/output/bar.rb', line 47 def self.register(output) output[:progress_bar] ||= output.style(:blue, :white) end |
Instance Method Details
#print(output) ⇒ Object
Print the progress bar to the output.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/sus/output/bar.rb', line 59 def print(output) width = output.width unless @total.zero? value = @current.to_f / @total.to_f else value = 0.0 end if @message = @message + MESSAGE_SUFFIX if .size > @maximum_message_width @maximum_message_width = .size end if @maximum_message_width < (width - MINIMUM_WIDTH) width -= @maximum_message_width = .rjust(@maximum_message_width) else @maximum_message_width = 0 = nil end end if output.write() end output.write( :progress_bar, draw(value, width), :reset, ) output.puts end |
#update(current, total, message) ⇒ Object
Update the progress bar values.
39 40 41 42 43 |
# File 'lib/sus/output/bar.rb', line 39 def update(current, total, ) @current = current @total = total @message = end |