Class: Omnizip::Progress::ProgressBar

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(width: nil, use_color: true) ⇒ ProgressBar

Initialize a new progress bar

Parameters:

  • width (Integer) (defaults to: nil)

    Bar width in characters (auto-detect if nil)

  • use_color (Boolean) (defaults to: true)

    Enable color output



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_colorObject (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

#widthObject (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

#clearString

Clear the progress bar line

Returns:

  • (String)

    Clear string



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

Parameters:

Returns:

  • (String)

    Formatted progress bar



30
31
32
33
34
35
# File 'lib/omnizip/progress/progress_bar.rb', line 30

def render(progress)
  bar = build_bar(progress.percentage)
  info = build_info(progress)

  "\r#{bar} #{info}"
end