Problem: Long-running commands block until completion; no way to see progress.
Solution: Add callbacks for real-time output processing.
# Stream output as it arrives
sh do
make("build", _on_stdout: ->(chunk) { print chunk })
end
# Progress tracking
lines_processed = 0
sh do
find(".", name: "*.log", _on_stdout: ->(chunk) {
lines_processed += chunk.count("\n")
print "\rProcessed #{lines_processed} files..."
})
end
puts "\nDone!"
# Early termination
sh do
tail("-f", "app.log", _on_stdout: ->(chunk) {
raise StopIteration if chunk.include?("ERROR")
print chunk
})
end
Variants
make("build", _on_stdout: ->(chunk) { print chunk })
make("build", _on: { stdout: ->(chunk) { print chunk }})
make!("build").on_stdout do |chunk|
print chunk
end.exec
make!("build").on_stdout do |chunk|
print chunk
end.on_stderr do |chunk|
print chunk
end.exec
make!("build").on(:stdout) do |chunk|
print chunk
end.exec
Implementation:
- Modify
TerminalExecutor.capture to yield chunks during IO.select loop
- Support
_on_stdout, _on_stderr, _on_output (both) callbacks
- Handle
StopIteration for early termination
Problem: Long-running commands block until completion; no way to see progress.
Solution: Add callbacks for real-time output processing.
Variants
Implementation:
TerminalExecutor.captureto yield chunks during IO.select loop_on_stdout,_on_stderr,_on_output(both) callbacksStopIterationfor early termination