Class: Clack::Prompts::Progress
- Inherits:
-
Object
- Object
- Clack::Prompts::Progress
- Defined in:
- lib/clack/prompts/progress.rb
Overview
Instance Method Summary collapse
-
#advance(amount = 1) ⇒ self
Advance progress by the given amount.
-
#error(message = nil) ⇒ self
Complete with error state.
-
#initialize(total:, message: nil, output: $stdout) ⇒ Progress
constructor
A new instance of Progress.
-
#message(msg) ⇒ self
Update the message without changing progress.
-
#start(message = nil) ⇒ self
Start displaying the progress bar.
-
#stop(final_message = nil) ⇒ self
Complete with success.
-
#update(current) ⇒ self
Set progress to an absolute value.
Constructor Details
#initialize(total:, message: nil, output: $stdout) ⇒ Progress
Returns a new instance of Progress.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/clack/prompts/progress.rb', line 30 def initialize(total:, message: nil, output: $stdout) raise ArgumentError, "total must be non-negative" if total.negative? @total = total @current = 0 @message = @output = output @started = false @width = 40 @last_frame = nil end |
Instance Method Details
#advance(amount = 1) ⇒ self
Advance progress by the given amount.
57 58 59 60 61 |
# File 'lib/clack/prompts/progress.rb', line 57 def advance(amount = 1) @current = [@current + amount, @total].min render self end |
#error(message = nil) ⇒ self
Complete with error state.
98 99 100 101 102 |
# File 'lib/clack/prompts/progress.rb', line 98 def error( = nil) @message = if render_final(:error) self end |
#message(msg) ⇒ self
Update the message without changing progress.
77 78 79 80 81 |
# File 'lib/clack/prompts/progress.rb', line 77 def (msg) @message = msg render self end |
#start(message = nil) ⇒ self
Start displaying the progress bar.
46 47 48 49 50 51 |
# File 'lib/clack/prompts/progress.rb', line 46 def start( = nil) @message = if @started = true render self end |
#stop(final_message = nil) ⇒ self
Complete with success. Sets progress to 100%.
87 88 89 90 91 92 |
# File 'lib/clack/prompts/progress.rb', line 87 def stop( = nil) @current = @total @message = if render_final(:success) self end |
#update(current) ⇒ self
Set progress to an absolute value.
67 68 69 70 71 |
# File 'lib/clack/prompts/progress.rb', line 67 def update(current) @current = [current, @total].min render self end |