Module: Dapp::Project::Logging::Paint

Included in:
Dapp::Project
Defined in:
lib/dapp/project/logging/paint.rb

Overview

Paint

Constant Summary collapse

FORMAT =
{
  step: [:yellow, :bold],
  info: [:blue],
  success: [:green, :bold],
  warning: [:red, :bold],
  secondary: [:white, :bold],
  default: [:white]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



40
41
42
# File 'lib/dapp/project/logging/paint.rb', line 40

def included(base)
  base.extend(self)
end

.initialize(mode) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/dapp/project/logging/paint.rb', line 16

def self.initialize(mode)
  ::Paint.mode = case mode
                 when 'auto' then STDOUT.tty? ? 8 : 0
                 when 'on'   then 8
                 when 'off'  then 0
                 else raise
                 end
end

Instance Method Details

#paint_string(object, style_name) ⇒ Object



31
32
33
# File 'lib/dapp/project/logging/paint.rb', line 31

def paint_string(object, style_name)
  ::Paint[unpaint(object.to_s), *paint_style(style_name)]
end

#paint_style(name) ⇒ Object



25
26
27
28
29
# File 'lib/dapp/project/logging/paint.rb', line 25

def paint_style(name)
  FORMAT[name].tap do |format|
    raise if format.nil?
  end
end

#unpaint(str) ⇒ Object



35
36
37
# File 'lib/dapp/project/logging/paint.rb', line 35

def unpaint(str)
  ::Paint.unpaint(str)
end