Class: Omnizip::Progress::ProgressBar
- Inherits:
-
Object
- Object
- Omnizip::Progress::ProgressBar
- Defined in:
- lib/omnizip/progress/progress_bar.rb
Overview
Visual progress bar for terminal output.
This class renders a progress bar with percentage, file counts, rate, and ETA information. It supports color output and automatic width detection.
Instance Attribute Summary collapse
-
#use_color ⇒ Object
readonly
Returns the value of attribute use_color.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#clear ⇒ String
Clear the progress bar line.
-
#initialize(width: nil, use_color: true) ⇒ ProgressBar
constructor
Initialize a new progress bar.
-
#render(progress) ⇒ String
Render progress bar string.
Constructor Details
#initialize(width: nil, use_color: true) ⇒ ProgressBar
Initialize a new progress bar
21 22 23 24 |
# File 'lib/omnizip/progress/progress_bar.rb', line 21 def initialize(width: nil, use_color: true) @width = width || detect_terminal_width @use_color = use_color && color_supported? end |
Instance Attribute Details
#use_color ⇒ Object (readonly)
Returns the value of attribute use_color.
15 16 17 |
# File 'lib/omnizip/progress/progress_bar.rb', line 15 def use_color @use_color end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
15 16 17 |
# File 'lib/omnizip/progress/progress_bar.rb', line 15 def width @width end |
Instance Method Details
#clear ⇒ String
Clear the progress bar line
40 41 42 |
# File 'lib/omnizip/progress/progress_bar.rb', line 40 def clear "\r#{' ' * width}\r" end |
#render(progress) ⇒ String
Render progress bar string
30 31 32 33 34 35 |
# File 'lib/omnizip/progress/progress_bar.rb', line 30 def render(progress) = (progress.percentage) info = build_info(progress) "\r#{} #{info}" end |