Class: CobraCommander::Executor::BufferedPrinter

Inherits:
TTY::Command::Printers::Null
  • Object
show all
Defined in:
lib/cobra_commander/executor/buffered_printer.rb

Constant Summary collapse

TIME_FORMAT =
"Finished in %5.3fs"

Instance Method Summary collapse

Constructor Details

#initializeBufferedPrinter

Returns a new instance of BufferedPrinter.



8
9
10
11
12
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 8

def initialize(*)
  super

  @buffers = Hash.new { |h, k| h[k] = StringIO.new }
end

Instance Method Details



22
23
24
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 22

def print_command_err_data(cmd, *args)
  write(cmd, args.join)
end


31
32
33
34
35
36
37
38
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 31

def print_command_exit(cmd, status, runtime, *)
  message = TIME_FORMAT % runtime
  message << " with exit status #{status}" if status

  output.puts @buffers.delete(cmd.uuid).string
  output.puts decorate(message, status == 0 ? :green : :red)
  output.puts
end


18
19
20
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 18

def print_command_out_data(cmd, *args)
  write(cmd, args.join)
end


26
27
28
29
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 26

def print_command_start(cmd, *args)
  message = "Running #{decorate(cmd.to_command, :yellow, :bold)} #{args.join(' ')}"
  write(cmd, message)
end

#write(cmd, message) ⇒ Object



14
15
16
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 14

def write(cmd, message)
  @buffers[cmd.uuid].write message
end