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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out, err) ⇒ Outputter

Returns a new instance of Outputter.



68
69
70
# File 'lib/chef/formatters/base.rb', line 68

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

Instance Attribute Details

#errObject (readonly)

Returns the value of attribute err.



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

def err
  @err
end

#outObject (readonly)

Returns the value of attribute out.



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

def out
  @out
end

Instance Method Details

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



79
80
81
82
83
84
85
# File 'lib/chef/formatters/base.rb', line 79

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

#highlineObject



72
73
74
75
76
77
# File 'lib/chef/formatters/base.rb', line 72

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

#puts(string, *colors) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/chef/formatters/base.rb', line 89

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