Class: Fatty::Terminal::Progress
- Inherits:
-
Object
- Object
- Fatty::Terminal::Progress
- Defined in:
- lib/fatty/terminal/progress.rb
Constant Summary collapse
- PARTIAL_BLOCKS =
["", "▏", "▎", "▍", "▌", "▋", "▊", "▉"].freeze
- FULL_BLOCK =
"█"- EMPTY_BAR =
"."- SHADE_EMPTY =
"░"- SHADE_HALF =
"▒"- SHADE_FULL =
"▓"- BRAILLE_STEPS =
["⠀", "⣀", "⣄", "⣆", "⣇", "⣧", "⣷", "⣿"].freeze
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#terminal ⇒ Object
readonly
Returns the value of attribute terminal.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #clear ⇒ Object
- #finish(message = nil, clear: false, role: @role, render: false, transient: true) ⇒ Object
-
#initialize(terminal:, label:, total: nil, style: :percent, role: :info, width: 40) ⇒ Progress
constructor
The width parameter's purpose varies by style:.
- #update(current: nil, total: @total, label: @label, indicator: nil, render: false) ⇒ Object
Constructor Details
#initialize(terminal:, label:, total: nil, style: :percent, role: :info, width: 40) ⇒ Progress
The width parameter's purpose varies by style:
:trail width = max visible width of the trail portion :bar width = max bar width :unicode_bar width = max bar width :braille_bar width = max bar width :spinner width ignored, unless later used for suffix/trail :count width ignored :percent width ignored
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fatty/terminal/progress.rb', line 27 def initialize(terminal:, label:, total: nil, style: :percent, role: :info, width: 40) @terminal = terminal @label = label.to_s @total = total&.to_i @style = style.to_sym @role = role @width = width.to_i @trail = [] @current = 0 @spinner_index = 0 validate_total_requirement! refresh end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
16 17 18 |
# File 'lib/fatty/terminal/progress.rb', line 16 def label @label end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
16 17 18 |
# File 'lib/fatty/terminal/progress.rb', line 16 def role @role end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
16 17 18 |
# File 'lib/fatty/terminal/progress.rb', line 16 def style @style end |
#terminal ⇒ Object (readonly)
Returns the value of attribute terminal.
16 17 18 |
# File 'lib/fatty/terminal/progress.rb', line 16 def terminal @terminal end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
16 17 18 |
# File 'lib/fatty/terminal/progress.rb', line 16 def total @total end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
16 17 18 |
# File 'lib/fatty/terminal/progress.rb', line 16 def width @width end |
Instance Method Details
#clear ⇒ Object
76 77 78 79 |
# File 'lib/fatty/terminal/progress.rb', line 76 def clear terminal.clear_status self end |
#finish(message = nil, clear: false, role: @role, render: false, transient: true) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fatty/terminal/progress.rb', line 59 def finish( = nil, clear: false, role: @role, render: false, transient: true) if clear terminal.clear_status else text = if && !.empty? render_text(suffix: ) else render_text end terminal.set_status(text, role: role, transient: transient) end terminal.render_now if render self end |
#update(current: nil, total: @total, label: @label, indicator: nil, render: false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fatty/terminal/progress.rb', line 43 def update(current: nil, total: @total, label: @label, indicator: nil, render: false) @current = current.to_i unless current.nil? @total = total&.to_i @label = label.to_s if style == :spinner advance_spinner else append_indicator(indicator) end refresh terminal.render_now if render self end |