Class: Bosh::Cli::TaskTracking::StageProgressBar
- Defined in:
- lib/cli/task_tracking/stage_progress_bar.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.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 11 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.
7 8 9 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 7 def @bar_visible end |
#current ⇒ Object
Returns the value of attribute current.
5 6 7 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 5 def current @current end |
#finished_steps ⇒ Object
Returns the value of attribute finished_steps.
8 9 10 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 8 def finished_steps @finished_steps end |
#label ⇒ Object
Returns the value of attribute label.
6 7 8 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 6 def label @label end |
#terminal_width ⇒ Object
Returns the value of attribute terminal_width.
9 10 11 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 9 def terminal_width @terminal_width end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 4 def title @title end |
#total ⇒ Object
Returns the value of attribute total.
3 4 5 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 3 def total @total end |
Instance Method Details
#bar ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 31 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
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 46 def calculate_terminal_width if ENV['COLUMNS'].to_s =~ /^\d+$/ ENV['COLUMNS'].to_i elsif !ENV['TERM'].blank? width = `tput cols` $?.exitstatus == 0 ? [width.to_i, 100].min : 80 else 80 end rescue 80 end |
#clear_line ⇒ Object
40 41 42 43 44 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 40 def clear_line @output.print("\r") @output.print(' ' * @terminal_width) @output.print("\r") end |
#refresh ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/cli/task_tracking/stage_progress_bar.rb', line 22 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 |