Class: Omnizip::Progress::ConsoleReporter

Inherits:
ProgressReporter show all
Defined in:
lib/omnizip/progress/console_reporter.rb

Overview

Progress reporter that displays a progress bar in the console.

This reporter uses ProgressBar to render a visual progress bar in the terminal, with automatic TTY detection and color support.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout, width: nil, use_color: true) ⇒ ConsoleReporter

Initialize a new console reporter

Parameters:

  • output (IO) (defaults to: $stdout)

    Output stream (default: $stdout)

  • width (Integer) (defaults to: nil)

    Bar width (auto-detect if nil)

  • use_color (Boolean) (defaults to: true)

    Enable color output



21
22
23
24
25
26
# File 'lib/omnizip/progress/console_reporter.rb', line 21

def initialize(output: $stdout, width: nil, use_color: true)
  super()
  @output = output
  @progress_bar = ProgressBar.new(width: width, use_color: use_color)
  @started = false
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



14
15
16
# File 'lib/omnizip/progress/console_reporter.rb', line 14

def output
  @output
end

#progress_barObject (readonly)

Returns the value of attribute progress_bar.



14
15
16
# File 'lib/omnizip/progress/console_reporter.rb', line 14

def progress_bar
  @progress_bar
end

Instance Method Details

#finish(_progress) ⇒ Object

Called when operation completes

Parameters:



49
50
51
52
53
54
55
56
# File 'lib/omnizip/progress/console_reporter.rb', line 49

def finish(_progress)
  return unless output.tty? && @started

  # Clear the progress bar and print newline
  output.print progress_bar.clear
  output.puts
  output.flush
end

#report(progress) ⇒ Object

Report progress to console

Parameters:



31
32
33
34
35
36
37
# File 'lib/omnizip/progress/console_reporter.rb', line 31

def report(progress)
  return unless output.tty?

  @started = true
  output.print progress_bar.render(progress)
  output.flush
end

#start(_progress) ⇒ Object

Called when operation starts

Parameters:



42
43
44
# File 'lib/omnizip/progress/console_reporter.rb', line 42

def start(_progress)
  @started = false
end