Class: Bosh::Cli::StageProgressBar
- Defined in:
- lib/cli/event_log_renderer.rb
Instance Attribute Summary collapse
-
#bar_visible ⇒ Object
Returns the value of attribute bar_visible.
-
#current ⇒ Object
Returns the value of attribute current.
-
#finished_steps ⇒ Object
Returns the value of attribute finished_steps.
-
#label ⇒ Object
Returns the value of attribute label.
-
#terminal_width ⇒ Object
Returns the value of attribute terminal_width.
-
#title ⇒ Object
Returns the value of attribute title.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #bar ⇒ Object
- #calculate_terminal_width ⇒ Object
- #clear_line ⇒ Object
-
#initialize(output) ⇒ StageProgressBar
constructor
A new instance of StageProgressBar.
- #refresh ⇒ Object
Constructor Details
#initialize(output) ⇒ StageProgressBar
Returns a new instance of StageProgressBar.
343 344 345 346 347 348 349 350 351 352 |
# File 'lib/cli/event_log_renderer.rb', line 343 def initialize(output) @output = output @current = 0 @total = 100 @bar_visible = true @finished_steps = 0 @filler = "o" @terminal_width = calculate_terminal_width @bar_width = (0.24 * @terminal_width).to_i # characters end |
Instance Attribute Details
#bar_visible ⇒ Object
Returns the value of attribute bar_visible.
339 340 341 |
# File 'lib/cli/event_log_renderer.rb', line 339 def @bar_visible end |
#current ⇒ Object
Returns the value of attribute current.
337 338 339 |
# File 'lib/cli/event_log_renderer.rb', line 337 def current @current end |
#finished_steps ⇒ Object
Returns the value of attribute finished_steps.
340 341 342 |
# File 'lib/cli/event_log_renderer.rb', line 340 def finished_steps @finished_steps end |
#label ⇒ Object
Returns the value of attribute label.
338 339 340 |
# File 'lib/cli/event_log_renderer.rb', line 338 def label @label end |
#terminal_width ⇒ Object
Returns the value of attribute terminal_width.
341 342 343 |
# File 'lib/cli/event_log_renderer.rb', line 341 def terminal_width @terminal_width end |
#title ⇒ Object
Returns the value of attribute title.
336 337 338 |
# File 'lib/cli/event_log_renderer.rb', line 336 def title @title end |
#total ⇒ Object
Returns the value of attribute total.
335 336 337 |
# File 'lib/cli/event_log_renderer.rb', line 335 def total @total end |
Instance Method Details
#bar ⇒ Object
363 364 365 366 367 368 369 370 |
# File 'lib/cli/event_log_renderer.rb', line 363 def n_fillers = @total == 0 ? 0 : [(@bar_width * (@current.to_f / @total.to_f)).floor, 0].max fillers = "#{@filler}" * n_fillers spaces = " " * [(@bar_width - n_fillers), 0].max "|#{fillers}#{spaces}|" end |
#calculate_terminal_width ⇒ Object
378 379 380 381 382 383 384 385 386 387 |
# File 'lib/cli/event_log_renderer.rb', line 378 def calculate_terminal_width if !ENV["TERM"].blank? width = `tput cols` $?.exitstatus == 0 ? [width.to_i, 100].min : 80 else 80 end rescue 80 end |
#clear_line ⇒ Object
372 373 374 375 376 |
# File 'lib/cli/event_log_renderer.rb', line 372 def clear_line @output.print("\r") @output.print(" " * @terminal_width) @output.print("\r") end |
#refresh ⇒ Object
354 355 356 357 358 359 360 361 |
# File 'lib/cli/event_log_renderer.rb', line 354 def refresh clear_line = @bar_visible ? : "" title_width = (0.35 * @terminal_width).to_i title = @title.truncate(title_width).ljust(title_width) @output.print "#{title} #{} #{@finished_steps}/#{@total}" @output.print " #{@label}" if @label end |