add colorization
This commit is contained in:
@@ -53,6 +53,7 @@ begin
|
|||||||
s.add_development_dependency 'rr', '~> 0.10.11'
|
s.add_development_dependency 'rr', '~> 0.10.11'
|
||||||
s.add_development_dependency 'rspec', '~> 2.0.0'
|
s.add_development_dependency 'rspec', '~> 2.0.0'
|
||||||
|
|
||||||
|
s.add_dependency 'term-ansicolor', '~> 1.0.5'
|
||||||
s.add_dependency 'thor', '~> 0.13.6'
|
s.add_dependency 'thor', '~> 0.13.6'
|
||||||
end
|
end
|
||||||
Jeweler::GemcutterTasks.new
|
Jeweler::GemcutterTasks.new
|
||||||
|
|||||||
+17
-2
@@ -2,12 +2,17 @@ require "foreman"
|
|||||||
require "foreman/process"
|
require "foreman/process"
|
||||||
require "pty"
|
require "pty"
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
|
require "term/ansicolor"
|
||||||
|
|
||||||
class Foreman::Engine
|
class Foreman::Engine
|
||||||
|
|
||||||
attr_reader :procfile
|
attr_reader :procfile
|
||||||
attr_reader :directory
|
attr_reader :directory
|
||||||
|
|
||||||
|
extend Term::ANSIColor
|
||||||
|
|
||||||
|
COLORS = [ cyan, yellow, green, magenta, on_blue ]
|
||||||
|
|
||||||
def initialize(procfile)
|
def initialize(procfile)
|
||||||
@procfile = read_procfile(procfile)
|
@procfile = read_procfile(procfile)
|
||||||
@directory = File.expand_path(File.dirname(procfile))
|
@directory = File.expand_path(File.dirname(procfile))
|
||||||
@@ -18,6 +23,7 @@ class Foreman::Engine
|
|||||||
procfile.split("\n").inject({}) do |hash, line|
|
procfile.split("\n").inject({}) do |hash, line|
|
||||||
next if line.strip == ""
|
next if line.strip == ""
|
||||||
process = Foreman::Process.new(*line.split(" ", 2))
|
process = Foreman::Process.new(*line.split(" ", 2))
|
||||||
|
process.color = next_color
|
||||||
hash.update(process.name => process)
|
hash.update(process.name => process)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -82,14 +88,17 @@ private ######################################################################
|
|||||||
def kill_and_exit(signal="TERM")
|
def kill_and_exit(signal="TERM")
|
||||||
info "termination requested"
|
info "termination requested"
|
||||||
running_processes.each do |pid, process|
|
running_processes.each do |pid, process|
|
||||||
info "killing pid #{pid}", process
|
info "killing #{process.name} in pid #{pid}"
|
||||||
Process.kill(signal, pid)
|
Process.kill(signal, pid)
|
||||||
end
|
end
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def info(message, process=nil)
|
def info(message, process=nil)
|
||||||
puts "[#{Time.now.strftime("%H:%M:%S")}] [#{process ? process.name : "system"}] #{message}"
|
print process.color if process
|
||||||
|
print "[#{Time.now.strftime("%H:%M:%S")}] [#{process ? process.name : "system"}] #{message.chomp}"
|
||||||
|
print Term::ANSIColor.reset
|
||||||
|
puts
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_info
|
def print_info
|
||||||
@@ -118,4 +127,10 @@ private ######################################################################
|
|||||||
@running_processes ||= {}
|
@running_processes ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def next_color
|
||||||
|
@current_color ||= -1
|
||||||
|
@current_color += 1
|
||||||
|
@current_color >= COLORS.length ? "" : COLORS[@current_color]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ class Foreman::Process
|
|||||||
|
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
attr_reader :command
|
attr_reader :command
|
||||||
|
attr_accessor :color
|
||||||
|
|
||||||
def initialize(name, command)
|
def initialize(name, command)
|
||||||
@name = name
|
@name = name
|
||||||
|
|||||||
Reference in New Issue
Block a user