Class: Chef::Formatters::Outputter

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/formatters/base.rb

Overview

Outputter

Handles basic printing tasks like colorizing. – TODO: Duplicates functionality from knife, upfactor.

Instance Method Summary collapse

Constructor Details

#initialize(out, err) ⇒ Outputter

Returns a new instance of Outputter.



65
66
67
# File 'lib/chef/formatters/base.rb', line 65

def initialize(out, err)
  @out, @err = out, err
end

Instance Method Details

#color(string, *colors) ⇒ Object Also known as: print



76
77
78
79
80
81
82
# File 'lib/chef/formatters/base.rb', line 76

def color(string, *colors)
  if Chef::Config[:color]
    @out.print highline.color(string, *colors)
  else
    @out.print string
  end
end

#highlineObject



69
70
71
72
73
74
# File 'lib/chef/formatters/base.rb', line 69

def highline
  @highline ||= begin
    require 'highline'
    HighLine.new
  end
end

#puts(string, *colors) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/chef/formatters/base.rb', line 86

def puts(string, *colors)
  if Chef::Config[:color]
    @out.puts highline.color(string, *colors)
  else
    @out.puts string
  end
end