Class: CobraCommander::Executor::BufferedPrinter
- Inherits:
-
TTY::Command::Printers::Null
- Object
- TTY::Command::Printers::Null
- CobraCommander::Executor::BufferedPrinter
- Defined in:
- lib/cobra_commander/executor/buffered_printer.rb
Constant Summary collapse
- TIME_FORMAT =
"Finished in %5.3fs"
Instance Method Summary collapse
-
#initialize ⇒ BufferedPrinter
constructor
A new instance of BufferedPrinter.
- #print_command_err_data(cmd, *args) ⇒ Object
- #print_command_exit(cmd, status, runtime) ⇒ Object
- #print_command_out_data(cmd, *args) ⇒ Object
- #print_command_start(cmd, *args) ⇒ Object
- #write(cmd, message) ⇒ Object
Constructor Details
#initialize ⇒ BufferedPrinter
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
#print_command_err_data(cmd, *args) ⇒ Object
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 |
#print_command_exit(cmd, status, runtime) ⇒ Object
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, *) = TIME_FORMAT % runtime << " with exit status #{status}" if status output.puts @buffers.delete(cmd.uuid).string output.puts decorate(, status == 0 ? :green : :red) output.puts end |
#print_command_out_data(cmd, *args) ⇒ Object
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 |
#print_command_start(cmd, *args) ⇒ Object
26 27 28 29 |
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 26 def print_command_start(cmd, *args) = "Running #{decorate(cmd.to_command, :yellow, :bold)} #{args.join(' ')}" write(cmd, ) end |
#write(cmd, message) ⇒ Object
14 15 16 |
# File 'lib/cobra_commander/executor/buffered_printer.rb', line 14 def write(cmd, ) @buffers[cmd.uuid].write end |