class Foreman::Engine::CLI

Constants

FOREMAN_COLORS

Public Instance Methods

output(name, data) click to toggle source
# File lib/foreman/engine/cli.rb, line 56
def output(name, data)
  data.to_s.lines.map(&:chomp).each do |message|
    output  = ""
    output += $stdout.color(@colors[name.split(".").first].to_sym)
    output += "#{Time.now.strftime("%H:%M:%S")} " if options[:timestamp]
    output += "#{pad_process_name(name)} | "
    output += $stdout.color(:reset)
    output += message
    $stdout.puts output
    $stdout.flush
  end
rescue Errno::EPIPE
  terminate_gracefully
end
shutdown() click to toggle source
# File lib/foreman/engine/cli.rb, line 71
def shutdown
end
startup() click to toggle source
# File lib/foreman/engine/cli.rb, line 50
def startup
  @colors = map_colors
  proctitle "foreman: main" unless Foreman.windows?
  Color.enable($stdout, options[:color])
end

Private Instance Methods

map_colors() click to toggle source
# File lib/foreman/engine/cli.rb, line 88
def map_colors
  colors = Hash.new("white")
  @names.values.each_with_index do |name, index|
    colors[name] = FOREMAN_COLORS[index % FOREMAN_COLORS.length]
  end
  colors["system"] = "bright_white"
  colors
end
name_padding() click to toggle source
# File lib/foreman/engine/cli.rb, line 76
def name_padding
  @name_padding ||= begin
    index_padding = @names.values.map { |n| formation[n] }.max.to_s.length + 1
    name_padding  = @names.values.map { |n| n.length + index_padding }.sort.last
    [ 6, name_padding.to_i ].max
  end
end
pad_process_name(name) click to toggle source
# File lib/foreman/engine/cli.rb, line 84
def pad_process_name(name)
  name.ljust(name_padding, " ")
end
proctitle(title) click to toggle source
# File lib/foreman/engine/cli.rb, line 97
def proctitle(title)
  $0 = title
end
termtitle(title) click to toggle source
# File lib/foreman/engine/cli.rb, line 101
def termtitle(title)
  printf("\033]0;#{title}\007") unless Foreman.windows?
end