Skip to content

[Feature Idea] Output Streaming #32

@albertalef

Description

@albertalef

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions