Class: NattyUI::Progress
- Defined in:
- lib/natty-ui/progress.rb
Overview
A Temporary element that displays an progress indicator.
Instances are created by Features#progress. When a max value is set the
progress is displayed as a percentage bar that fills as #value increases.
Without a max, an open-ended dot animation grows.
All Features methods are available on this element, making it possible to nest output or sub-tasks inside a progress block.
Instance Attribute Summary collapse
-
#max ⇒ Numeric?
readonly
Maximum value set at creation time.
-
#value ⇒ Numeric
Current progress value.
Instance Method Summary collapse
-
#step(*title, count: 1, **popts) ⇒ Progress
Increments the progress value and optionally updates the title.
-
#update(*title, value: nil, **popts) ⇒ Progress
Updates the progress title and/or value.
Instance Attribute Details
#max ⇒ Numeric? (readonly)
Maximum value set at creation time.
29 30 31 |
# File 'lib/natty-ui/progress.rb', line 29 def max @max end |
#value ⇒ Numeric
Current progress value.
When #max is set the value is clamped to 0..max. When there is no
maximum the value is clamped to a minimum of 0. Setting the same
value twice is a no-op.
41 42 43 |
# File 'lib/natty-ui/progress.rb', line 41 def value @value end |
Instance Method Details
#step(*title, count: 1, **popts) ⇒ Progress
Increments the progress value and optionally updates the title.
92 93 94 |
# File 'lib/natty-ui/progress.rb', line 92 def step(*title, count: 1, **popts) update(*title, value: @value + count, **popts) end |
#update(*title, value: nil, **popts) ⇒ Progress
Updates the progress title and/or value.
Any number of the positional title arguments and the value: keyword
may be omitted independently.
70 71 72 73 74 75 |
# File 'lib/natty-ui/progress.rb', line 70 def update(*title, value: nil, **popts) return if @done != 0 draw_title(*title, **popts) unless title.empty? self.value = value if value self end |