Module: Capistrano::Configuration::Actions::Inspect

Defined in:
lib/capistrano/colorized_stream.rb

Instance Method Summary collapse

Instance Method Details

#stream_with_colorized(command, options = {}) ⇒ Object Also known as: stream



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/capistrano/colorized_stream.rb', line 12

def stream_with_colorized(command, options={})
  trap("INT") { puts 'Interupted'; exit 0; }

  previous_last_line = Hash.new("")
  invoke_command(command, options) do |ch, stream, out|
    if stream == :out
      hostname = ch[:host]
      # split to lines and take care of the previous last line which was not outputted
      lines = out.split(/\r?\n/m, -1)
      lines[0] = previous_last_line[hostname] + lines[0]
      previous_last_line[hostname] = lines.pop

      # puts with colorized hostname
      lines.each {|line| puts colorized(hostname) + line }
    end
    warn "[err :: #{ch[:server]}] #{out}" if stream == :err
  end
end