Class: Clack::Prompts::Tasks
- Inherits:
-
Object
- Object
- Clack::Prompts::Tasks
- Defined in:
- lib/clack/prompts/tasks.rb
Overview
Sequential task runner with spinner animation.
Runs tasks in order, showing a spinner while each runs. Displays success/error status after each task completes.
Each task is a hash with:
:title- display title:task- Proc to execute (exceptions are caught). Optionally accepts a message-update callable to change the spinner message mid-execution.:enabled- optional boolean (default true). When false, the task is skipped entirely.
Defined Under Namespace
Classes: Task, TaskResult
Instance Method Summary collapse
-
#initialize(tasks:, output: $stdout) ⇒ Tasks
constructor
A new instance of Tasks.
-
#run ⇒ Array<TaskResult>
Run all tasks sequentially.
Constructor Details
#initialize(tasks:, output: $stdout) ⇒ Tasks
Returns a new instance of Tasks.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/clack/prompts/tasks.rb', line 68 def initialize(tasks:, output: $stdout) @tasks = tasks.map do |task_data| Task.new( title: task_data[:title], task: task_data[:task], enabled: task_data.fetch(:enabled, true) ) end @output = output @results = [] end |
Instance Method Details
#run ⇒ Array<TaskResult>
Run all tasks sequentially.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/clack/prompts/tasks.rb', line 83 def run @output.print Core::Cursor.hide @tasks.each do |task| next unless task.enabled run_task(task) end @results ensure begin @output.print Core::Cursor.show rescue IOError, SystemCallError # output stream already closed end end |