Class: Console::Terminal::Formatter::Spawn

Inherits:
Object
  • Object
show all
Defined in:
lib/console/terminal/formatter/spawn.rb

Overview

Format a spawn event, including the command and arguments.

Constant Summary collapse

KEY =

The key used to identify this formatter.

:spawn

Instance Method Summary collapse

Constructor Details

#initialize(terminal) ⇒ Spawn

Create a new spawn formatter.

Parameters:



17
18
19
20
# File 'lib/console/terminal/formatter/spawn.rb', line 17

def initialize(terminal)
  @terminal = terminal
  @terminal[:spawn_command] ||= @terminal.style(:blue, nil, :bold)
end

Instance Method Details

#format(event, stream, verbose: false, width: 80) ⇒ Object

Format the given event.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/console/terminal/formatter/spawn.rb', line 28

def format(event, stream, verbose: false, width: 80)
  environment, arguments, options = event.values_at(:environment, :arguments, :options)
  
  arguments = arguments.flatten.collect(&:to_s)
  
  stream.puts "#{@terminal[:spawn_command]}#{arguments.join(' ')}#{@terminal.reset}#{chdir_string(options)}"
  
  if verbose and environment
    environment.each do |key, value|
      stream.puts "export #{key}=#{value}"
    end
  end
end