Class: Omnizip::Progress::ConsoleReporter
- Inherits:
-
ProgressReporter
- Object
- ProgressReporter
- Omnizip::Progress::ConsoleReporter
- 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
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#progress_bar ⇒ Object
readonly
Returns the value of attribute progress_bar.
Instance Method Summary collapse
-
#finish(_progress) ⇒ Object
Called when operation completes.
-
#initialize(output: $stdout, width: nil, use_color: true) ⇒ ConsoleReporter
constructor
Initialize a new console reporter.
-
#report(progress) ⇒ Object
Report progress to console.
-
#start(_progress) ⇒ Object
Called when operation starts.
Constructor Details
#initialize(output: $stdout, width: nil, use_color: true) ⇒ ConsoleReporter
Initialize a new console reporter
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
#output ⇒ Object (readonly)
Returns the value of attribute output.
14 15 16 |
# File 'lib/omnizip/progress/console_reporter.rb', line 14 def output @output end |
#progress_bar ⇒ Object (readonly)
Returns the value of attribute progress_bar.
14 15 16 |
# File 'lib/omnizip/progress/console_reporter.rb', line 14 def @progress_bar end |
Instance Method Details
#finish(_progress) ⇒ Object
Called when operation completes
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 .clear output.puts output.flush end |
#report(progress) ⇒ Object
Report progress to console
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 .render(progress) output.flush end |
#start(_progress) ⇒ Object
Called when operation starts
42 43 44 |
# File 'lib/omnizip/progress/console_reporter.rb', line 42 def start(_progress) @started = false end |